For the past few weeks, I’ve felt a need to do something new - shake things up; that sort of thing. I’ve also been yearning to learn a new programming language. I finally settled on learning node.js and to explore how it runs on a Raspberry Pi (RPi).

I’m the kind who likes to kick off a project in order to learn a new technology and so, after some thinking I decided on what my project was going to be.

The Project

One of my big gripes with flight simulation is the absence of actual equipment that you can interact with to perform flight functions. While every self-respecting flight simulation set up includes the control yoke and rudder pedals, most of them do not include things like a radio console, or switches, that you can interact with during flight. The result is that the “pilot” ends up using his/her mouse to control the simulator’s functions and that reduces the realism of the experience significantly.

The project I decided to work on was a Radio and Switch Panel for my flight simulator. I will describe the radio panel in more detail in a subsequent post and focus, instead, on actually setting up Node.js on the RPi in this post.

Installing Node.js

There are two methods to installing node.js on the RPi:

  • Using a pre-built .deb package.
  • Installing from a tarball.

Method 1: Using a .deb package

Pre-built .deb packages of the latest node.js are available at http://node-arm.herokuapp.com/. The steps to follow to install the latest LTS (4.2.1) version of node are:

  1. Upgrade to the Debian Jessie release (the most recent Raspbian uses Jessie).
  2. Download the latest node-arm node.js distribution. $ wget http://node-arm.herokuapp.com/node_latest_armhf.deb
  3. Install the .deb package: $ sudo dpkg -i node_latest_armhf.deb
  4. Test that your installation was successful: $ node -v

You should see something like v4.2.1 printed out on your console.

Method 2: Install using a tarball

Binary tarballs of both the LTS (4.2.2), and the Stable (5.1.0) versions of node.js are available from the nodejs.org download site at https://nodejs.org/dist/v4.2.2 or https://nodejs.org/dist/v5.1.0

The steps to follow to install node.js from these distributions are:

  1. Upgrade to the Debian Jessie release (the most recent Raspbian uses Jessie).
  2. Determine which ARM processor version you have: $ uname -mrs Linux 4.1.7-v7+ armv7l Look for the phrase arm followed by a “vXX”. In my case (the Raspberry Pi 2 Model B) the processor is an ARM v71 processor.
  3. Download the appropriate tarball: $ wget https://nodejs.org/dist/v4.2.2/node-v4.2.2-linux-armv7l.tar.gz
  4. Install the distribution. I prefer to install it to /usr/local: tar xvzf node-v4.2.2-linux-armv7l.tar.gz --directory /usr/local --strip-components=1 The strip-components=1 option in the command above strips the first entry from the directory structure in the tarball. If you omit this option, tar creates a directory called node-v4.2.2-linux-armv71 inside </usr/local. That is not what we want. Hence, the use of the strip-components option.
  5. Test your installation: $ node -v v4.2.2

That concludes our short discussion on how to install node.js on a Raspberry Pi.