Setup a Node server on the Pi's most efficient OS.

Setup a Node server on the Pi's most efficient OS.

The Raspberry Pi is amazing. It's versatile, small and lightweight energy footprint for only $35 makes it a perfect choice for self hosted Node projects.

When it comes to operating systems to run on the Pi, it is easy to become overwhelmed by choices. Raspbian, OpenElec, Debian, RaspBMC, Arch, Pidora to name a few, how do you know which OS best fits your needs? Most of these systems are bloated, heavy and cumbersome for use as a server, and this is where MiniBian comes in.

MiniBian is Raspbian based and touts an amazing 15-second boot time, 31MB RAM usage, and consists of only 477MB fully installed, (Yes, it fits on a 1GB card) making it the perfect choice to host a NodeJS server. The following guide will help you get set up in no time.

Download Minibian here

Burn the image onto a SD card of 1GB+. There are several methods for burning images onto SD cards, but my personal favorite is PiFiller as it provides an interactive step-through menu.

Log into the Pi. Either with a keyboard & monitor, or using ssh (remotely logging into the terminal using Mac/Linux's terminal app). In this example, we will be using SSH. Be sure to replace https://www.garudax.id/redir/invalid-link-page?url=192%2e168%2e1%2e132 with the local IP address of your Pi. If you do not know what this is, you can either check your router page, or use PiFinder to find the IP address.

ssh root@192.168.1.132
password: raspberry

Change your password. This is not an option. Exposed Pi's to the internet or the network can easily be penetrated. The Pi has a common MAC address and hostname that can be identified by any IT level intelligent person, and the default password is in every brute-force password file out there. Luckily it is very easy.

passwd

Install packages in preparation for NodeJS. We only need 4 packages on Minibian to install Node. Sudo is not installed by default and can cause problems in the future if you follow other guides. Might as well fix that here and now.

apt-get update
apt-get install -y sudo wget curl xz-utils
# Optional. Can make life easier
apt-get install -y build-essential screen vim

Download, Extract and Copy. We obtain Node from the official website, extract it using the program tar, and copy all the files in the extracted directory into /usr/local/.

wget https://nodejs.org/dist/v6.9.5/node-v6.9.5-linux-armv6l.tar.xz
tar xf node-v6.9.5-linux-armv6l.tar.xz
cd node-v6.9.5-linux-armv6l
sudo cp -R * /usr/local/

Create Symbolic links to Node. Where is node? Why doesn't "node --version" or "npm --version" work? Well, this specific version of Debian, Minibian, is a bit different. Therefore we need to create symbolic links that point to the node & npm binaries. (A symbolic link is basically a shortcut).

ln -s /usr/local/bin/node /usr/sbin/node
ln -s /usr/local/bin/npm /usr/sbin/npm

Give it a try! If node and npm return their respective versions, then you are all set! Done. Complete. However, there are two more things we could do to tidy things up.

node -v && npm -v

Cleanup (optional)

cd ..
rm -r node-v6.9.5-linux-armv6l
rm node-v6.9.5-linux-armv6l.tar.xz

Install Forever (optional). Forever is a handy tool I discovered a while back. If for any reason, your Node program fails and quits, Forever will upstart your application again. Perfect for IRC bots or IoT projects! The syntax is very simple and once installed, is accessible anywhere in the OS.

npm install -g forever

# To use Forever, simply start your application with 'Forever start' instead of 'node'
forever start index.js

Thats it! If you found this guide helpful, please let me know. If you have any recommendations on guides in this style, I am also up for recommendations.

To view or add a comment, sign in

More articles by Indigo M.

  • A Super Quick Primer On Website Databases

    Let's say you are making a project and for some reason need a database on the frontend. Perhaps you want to cache…

  • Android without Google

    I have a Pixel 2 XL that I absolutely love. What drew me to the Pixel line of phones is that they are essentially pure…

    5 Comments
  • How I Fixed My Typing As An Adult

    Since I was a kid I have had terrible typing habits. Growing up we were forced to take typing classes to prepare us for…

    1 Comment
  • React Redux & Decorators

    Decorators are a great addition to Javascript. For those coding in React, we are already required to use some sort of…

  • Lets use Typescript

    Typescript improves Javascript by adding types to the language. Why would anyone bother to add types to a well…

  • My Adventures with Kids On Computers

    I found my way into the non-profit space purely by accident. When I was online, reading my daily blog sites, I came…

  • SSH into the Pi Zero W without adaptors!

    So here I am with the latest Raspberry Pi without any way to get into it. I forgot to buy adaptors and am waiting for…

    4 Comments

Explore content categories