NodeJS Dev Environment Setup Notes

Here be the basic commands to get a basic NodeJS development server set up in an Ubuntu virtual machine. As always, the lab notes series provides the basic commands for reference only.

"If you want to make an apple pie from scratch, you must first create the universe." – Carl Sagan

Set up a VM

You must first create a VM. I’m running the 32 bit version of Ubuntu on Virtualbox. The host system runs Ubuntu [64 bit].

Install Node and NPM

then make nodejs run as node

$ sudo apt-get update
$ sudo apt-get install nodejs
$ sudo apt-get install npm

$ sudo update-alternatives --install /usr/bin/node node /usr/bin/nodejs 10

Initiate Node Project

$ mkdir myapp
$ cd myapp
$ npm init

Install ExpressJS
$ npm install express —save

Create file app.js
$ sudo nano app.js

fill it with this

var express = require('express');
var app = express();

app.get('/', function (req, res) {
  res.send('Hello World!');

app.listen(3000, function () {
  console.log('Example app listening on port 3000!');

Install Zerotier

Zerotier allows you to run a software defined virtual network. Perfect for connecting your development VMs.

You can host your own Zerotier network controller, but for our purposes, the hosted network controller will work fine.

$ curl -s | bash

Then join the network

$ sudo zerotier-cli join [network id]

The member then needs to be approved in the Zerotier Central network panel.

You should now have a NodeJS server accessible from other devices on the virtual network.