Skip to content

How to setup node.js on a raspberry pi

The Raspberry Pi is a great device for tinkering and hacking around different technology and hardware.  This evening  I thought it might be fun to find out if I could get the Pi to host and run a web server developed using node.js. 

In this post I will provide a quick how to guide to set up a node.js web server on Raspberry Pi.

It turns out it is extremely easy to get the Pi to run node, due to the release of ARM-version of node ,  node-arm , and the installation is super easy, and we will walk-through the process of installing node-arm in this post.

If you haven't read my previous posts  on how to remotely access the raspberry pi via ssh or how to create a network shared folder on raspberry pi , then I suggest you do so because knowing how to access the pi via SSH and a network share are very handy in order to follow along with this guide.

Install Node.js on Raspberry Pi

We need to ensure the Pi is connected to the internet, because we are going to download and install node-arm. So we connect to the Pi using SSH and execute the following commands.

Shell

After this has completed you can check which version of node has been installed using the command below.

Shell

In my case the version is v0.10.33

node version check

Develop your web server

For this part I thought I would just run the lightweight web server I developed in a previous post - Simple lightweight node.js webserver

JS

We now need to copy the files over to the Raspberry Pi , and because my simple web server will be writing logs to a log file and using log4js we need to create the logs folder.

shared folder

We once again connect to the Pi using SSH to install log4js using the Node Package Manager (npm) onto the Pi.

Shell

We're now done with all our set up now we just need to run the web server and check it working

Shell

We will get informed the webserver is running

webserverrunning

We can access the the website using a browser. In my case my Pi is on the IP address of 192.168.0.37.

node site

We now have a node.js web server running on our Raspberry Pi.

Make the web server start on boot

If you want your web server to start up on boot you will need to node to run as the default user of Pi, because Pi has  Node in its path, the node command known

Shell

As per my set up I put the full file path to the webserver.js.

After you have completed all the requisites steps above, Node.js should now be installed  and you are now free to develop any software solution you choose using this javascript framework on you Pi.

Gary Woodfine
Latest posts by Gary Woodfine (see all)