node.js will serve as an intermediary between the final program we use, Node-Red, and the Arduino board running Firmata. In fact, Node-Red is basically just a front end for node.js, so anything we program in Node-Red can be run in node.js. In fact, I often run programs directly as a .js file to assist in debugging, as Node-Red isn't the best debugging environment at times. (See far below on how to do this, if you are as much of a beginner as I was).
I've detailed some resources under Further Resources to assist getting acquainted with node and how to install the various parts we'll eventually need below. This is all described for Windows, but it's not drastically different for Linux (I've installed it on a Raspberry Pi, which runs Debian, a version of Linux).
To install node.js, simply visit https://nodejs.org/en/ and install the LTS version (the full version is not needed for this project).
You install the various node.js libraries using a program called 'npm' - node package manager. It manages the various node.js libraries and packages available.
You must go to the directory you installed node.js in via a command prompt - the easiest way to do this is to use node.js's command prompt in your start menu. Another option is to hold Shift and right click in the node.js installation folder - the option to 'Open Command Window here' will appear.
Once you have a command prompt, you simply use the following command and you are on your way:
npm install -g packagename
I recommend installing all node packages with the '-g' added - this makes them global packages and prevented conflicts and dependency issues.
If you are behind a proxy (usually when you access the internet from work etc) you will need to tell npm this. You do this via a command prompt again and using the following commands:
npm config set proxy http://"username:password"@proxyaddress.up.ac.za:8080
npm config set https-proxy proxy http://"username:password"@proxyaddress.up.ac.za:8080
A recommended library of JavaScript functions is the Johnny-Five library ( http://johnny-five.io/ or https://github.com/rwaldron/johnny-five) which I've used extensively in this project. Johnny-Five is a Javascript library designed to control a number of boards, Arduino included, for the building of robots. As such the Johnny-Five library has a large number of functions to read sensors and control devices, ideal for a Laboratory automation and control.
Install globally using
npm install -g johnny-five
Note that wherever you run your node-red flows from or your JavaScript files will have to have Johnny-Five installed in that directory, so installing johnny-Five globally doesn't help much. I recommend using your .node-red user directory as your base of operations and install johnny-five there.
Serialport is a package needed to communicate using a USB cable via the serial protocol to your Arduino. Unfortunately it can be a real hassle to install (Ref: (https://github.com/EmergingTechnologyAdvisors/node-serialport)
Firstly your node.js needs to be the latest version, which if you have just recently installed should then be fine. ( Ref: https://github.com/EmergingTechnologyAdvisors/node-serialport/issues/673 ),
Then the command that seems to work is (Ref: https://github.com/EmergingTechnologyAdvisors/node-serialport/issues/874 )
npm install -g --unsafe-perm serialport
Good luck...
git allows npm to install a number of user created packages available on the internet, download and install it from https://git-scm.com/download/win.
Coming from a Mechanical Engineering background, I found it absolutely impossible to find information on how to actually run a simple JavaScript file. With only Matlab experience, the concept of running files from the command prompts (and not a nice program or IDE) was both foreign and confusing. What follows here is an absolute beginner's guide to running your first Javascipt file.
This example is basically how to get to the point to get an LED on a breadboard to blink - see http://node-ardx.org/exercises/1 for the full example (without this intro).