How to setup node.js on a raspberry pi

The Raspberry Pi is a great device for tinkering and hacking around.  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. 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.

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

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

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.

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

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

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

Freelance Full Stack Developer at threenine.co.uk
Helps businesses by improving their technical proficiencies and eliminating waste from the software development pipelines.

A unique background as business owner, marketing, software development and business development ensures that he can offer the optimum business consultancy services across a wide spectrum of business challenges.

Latest posts by Gary Woodfine (see all)

Affiliate Disclaimer

Disclosure: Please note that some of the links included in the blog posts are affiliate links, which means I will earn a commission if you decide to make a purchase.

I only include affiliate links to products, services and companies that I have personal experience and have actually used. I only recommend them because they are helpful and useful, not because of the small commissions I make if you decide to buy something.

Please do not spend any money on these products unless you feel they are relevant, suitable and will help you achieve your goals.

Buying anyone of these products and the commisions earned will not make me an overnite multi millionaire, but they will help to cover the hosting costs and compensate for the countless hours and effort I put in to create meaningful and valuable free content I provide to help others succeed.

You've also undoubtedly noticed that I also use various advertising networks - unless of of course you're using an Ad blocker, this is also an attempt to reduce my monthly deficit I experience in providing free relevant, valuable and on occassion insightful content for the benefit of others.

I only really make some money if people click on the ads, unless of course you consider 1c per 1000 impressions real money!

Bear in mind just how many impressions I need to make before I can cover my £20 hosting costs a month!

If you are using an adblocker and guilt stricken you can of course donate using any of the buttons below, but I won't be holding my breath.

Buy me a coffeeBuy me a coffee

π