View on GitHub

Node.js on Raspberry Pi

Web and Pi

Home

Description

Node.js is a JavaScript runtime environment for developing server-side Web applications. It uses an asynchronous event driven framework that is designed to build scalable network applications. I install it on nearly all of my pi to provide a framework for building user interfaces that can actually do something.

Learn more about node from Node.js, Express, Adafruit, and search.

Next up?

After reading this guide, you may be interested in reading:

Parts List

  • Installed network connected Raspberry Pi 2 or newer

Overview

Start with a Raspberry Pi image. This is an image saved after following the RPi Initial Setup Guide. This may be either a lite or a full desktop image.

  1. Write the image to the MicroSD.
  2. Connect to your Pi
  3. Download and install the nodejs binaries
  4. Express framework
  5. Node-RED
  6. Conclusion
  7. References

Write the image

Write the image to the MicroSD as described in the RPi Initial Setup Guide. Insert the MicroSD into the Pi and boot.

Connect Pi to your Internet

Use an Ethernet cable to connect the pi to the network. DHCP will assign the pi an IP address. Find the address of your pi from your network's DHCP server.

  • SSH to the pi at that IP address or yourpiname.local

Download and install the nodejs binaries

The pi uses the ARM processor. Determine which instruction set version is included, grep 'model name' /proc/cpuinfo. This output should include ARMv6, ARMv7, and so forth. The Raspberry Pi 3 uses the ARMv7 processor.

Visit the downloads page and select LTS Recommended for Most Users. Now copy the link to the correct ARM binary. In the following steps, replace node-v4.5.0-linux-armv7l with the version for your system.

  • Change to home directory on the pi, cd ~
  • Download the binary, wget https://nodejs.org/dist/v6.5.0/node-v6.5.0-linux-armv7l.tar.xz, replace the URL with the link you copied above.
  • Extract the binary, tar -xvf node-v6.5.0-linux-armv7l.tar.xz
  • cd node-v6.5.0-linux-armv7l
  • Copy the files, sudo cp -R * /usr/local/
  • Rehash the shell, hash -r
  • Check the version, node -v. This should match what you downloaded.
  • Check npm version, npm -v.

Express framework

Express.js is one of the most essential web frameworks for Node.js. It is a minimalist framework for building a host of web and mobile applications as well as application programming interfaces (APIs). Express.js is offers various features, like template engines, simplified multiple routing, database integration and more.

  • Install with sudo npm install express --save

References