This guide provides instructions on how to make Node.js modules available to Node-RED.
Steps:
1. Install the necessary Node.js package(s) on the target machine:
Note: Some Debian distributions require Node.js packages to be directly installed into Node Red’s node_modules directory. Navigate to it’s typical location by entering:
cd /var/lib/node-red/.node-red/node_modules
Then install packages by running:
sudo npm install {package name}
Please note that the device must have internet access to download npm packages.
2. Change to root user on the machine:
sudo -s
[sudo] password for debian:
3. Open the settings.js file with nano (or your favorite editor):
BeagleBone, Debian 10
cd /var/lib/node-red/.node-red
nano settings.js
4. Edit the settings.js file:
Modify the functionGlobalContext function in the settings file to reference modules of interest.
Below demonstrates the syntax for making the os, bonescript and moment node.js modules available to Node-RED.
(Tip: Make sure to use commas correctly).
functionGlobalContext: {
os:require('os'),
bonescript:require('bonescript'),
moment:require('moment')
// jfive:require("johnny-five"),
// j5board:require("johnny-five").Board({repl:false})
},
5. Save and exit the settings.js file.
6. Stop and start Node-RED for the changes to take effect.
BeagleBone, Debian 10
Stop Node-RED:
sudo systemctl stop nodered
Start Node-RED:
sudo systemctl start nodered