How to Setup Node.js on a Raspberry PI

In this short tutorial we’ll look at how to get Node running on your Raspberry PI, run it in the background and automatically have it start when the PI reboots.


First things first fire up a terminal or SSH into your PI and download the latest node tarball.
At the time of this writing that is v0.8.19 but of course substitute that with whatever version you choose.

$ wget
$ tar xvzf node-v0.8.19.tar.gz
$ cd node-v0.8.19

Next you’re ready to build Node from source.
On my Model B w/ 512MB of RAM this took about an hour and a half.

$ ./configure && make && sudo make install

If everything went ok you should now have node and npm installed on your PI.

$ node --version
$ npm --version

Cool, now let’s run a simple test app.
Create a new file and call it hello-node.js and paste the following into it:

// Load the http module to create an http server.
var http = require('http');
// Configure our HTTP server to respond with Hello World to all requests.
var server = http.createServer(function (request, response) {
   response.writeHead(200, {"Content-Type": "text/plain"});
   response.end("Hello World\n");
// Listen on port 8000, IP defaults to

Now start the server –

$ node ./hello.node.js

and navigate a browser to localhost:8000 and you should see “hello world” print to the screen.

Hurrah it works!

Ok, now let’s setup a daemon to run our node server outside of our shell and automatically have it start whenever the PI reboots.

First cd into /etc/init.d/ and create a new file called

$ cd /etc/init.d
$ sudo nano

Next copy the following into it:
Note to change the path_to_node_app variable to wherever your app lives.

#! /bin/sh
# /etc/init.d/node-server
# Provides:          node-server
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# change this to wherever your node app lives # 
# Carry out specific functions when asked to by the system
case "$1" in
    echo "* starting node-server * "
    echo "* starting node-server * [`date`]" >> /var/log/node-server.log
    /usr/local/bin/node $path_to_node_app >> /var/log/node-server.log 2>&1&
    echo "* stopping node-server * "
    echo "* stopping node-server * [`date`]" >> /var/log/node-server.log
    killall /usr/local/bin/node
    echo "Usage: /etc/init.d/node-server {start|stop}"
    exit 1
exit 0

Next we need to make this file executable via :

$ chmod 755 ./

Now let’s tell the PI to execute this script and start the server on reboot:

$ update-rc.d defaults

If we ever want to disable this just type :

$ update-rc.d -f remove

And lastly you can now start and stop your node server in the background anytime via :

# start-server #
sudo /etc/init.d/ start
# stop-server #
sudo /etc/init.d/ stop

I personally added aliases to these two commands in my ~/.bashrc

# start / stop node server in background #
alias nodestart='sudo /etc/init.d/ start'
alias nodestop='sudo /etc/init.d/ stop'
alias nodetail='tail -n100 /var/log/node-server.log'

So I can start / stop the server and view the log file simply by typing the following :

$ nodestart
$ nodestop
$ nodelog

And that’s about it. Any problems or questions feel free to post in the comments below.

  • Rob Dodson

    Just a heads up. If you don’t mind running a version of node that’s a few patches behind, there are precompiled binaries for the Pi. Might save you an hour or two of headaches :) seems to be the latest.

    • braitsch

      Cool! although there’s something magical about watching all that beautiful output to the console when building node from source :)

      • Rob Dodson

        true. plus it makes you look super badass if you’re doing it at the office :)

        • Rob Dodson

          Spent all day messing with those binaries only to have them not work. I guess it has to do with whichever version of raspbian they were compiled against? Following your instructions and just compiling from source was the only thing that worked for me. Thanks dude 😀

  • Harminder Singh Deol

    Just got back from work all tired and stuff, yet exited to install node.js, cause of all the youtube vedio of people controlling GPIO over the web. I am beginner to pi & javascript.
    So i was installing node.js and after about 40 min my screen went to sleep so i pressed some keys on the keyboard and stuff got written into the terminal. Before i could delete it the set up went to the next line. I got a warning saying something…. don’t remember but whole lot of lines with warning in them.
    So i just press ctrl+c, exit out of the installation
    then deleted the node-v0.8.19 folder
    and nw installing it again.
    Should i be worried!!!!!!!

  • Harminder Singh Deol

    I found an error in the post , To run the hello-node.js file, the file name needed to be corrected on the post between hello and node there is a period (.) but there should have been a (-)

    Now start the server –
    $ node ./hello.node.js