6. What is Node-RED?
• Wires together hardware devices, APIs and online
services.
• Flows and authentication held in JSON
• Event-driven
• Browser-based flow editor
6#engageug
7. Facts
• Origins from IBM Emerging Technologies (Nick O'Leary
and Dave Conway-Jones)
• On GitHub 2013
• Founding project of JS Foundation in 2016
• 1 million downloads
• 1700 third-party add-on nodes
• Currently version 0.20. Version 1.0 in beta during Engage.
7#engageug
8. Why Node-RED?
• Low code
• Easy install and run
• Open-source project on GitHub (Apache 2 license)
• You probably already know how to code it
• Easy to share solutions
• Library with ready made integrations points
8#engageug
9. Values for Domino
• Lots of third-party add-ons.
• Simplifies integration
• Dashboards
• Easy scheduling of JavaScript functions.
• node-red-contrib-dominodb
A simple-to-use NodeRED interface to the the dominodb nodeJS package
9#engageug
11. How and where
• Runs on Node.js
• Where Node.js runs. Linux preferred but Windows is
supported.
• AWS, IBM Cloud, MS Azure
• Devices like Raspberry Pi, Android, Arduino
11#engageug
12. What Are Nodes
• Nodes are asynchronous black boxes
• Can use flow, sub-flow, global and configuration object
• Passes data in a msg object
• Flows and authentication held in JSON
• Nodes coded with HTML and JavaScript
12#engageug
14. Local installation
• Getting started: https://nodered.org/docs/getting-
started/installation
• Installing on Windows: Getting started:
https://nodered.org/docs/getting-started/installation
14#engageug
15. Install Node.js
• Get Node.js from https://nodejs.org/en/
• Run installation as administrator
• Accept defaults
15#engageug
16. Install Node-RED
• Run cmd
• Execute: npm install -g --unsafe-perm node-red
• Run “node-red”
• Node-RED will create a new folder in your
%HOMEPATH% folder called .node-red
• Point a local browser at http://localhost:1880
16#engageug
19. Fundamentals - Nodes
• Input nodes
- one output endpoint *
- button to actuate
• Output nodes
- one input endpoint *
- button to enable/disable
• Processing nodes
- one input and one or more output endpoints
* One endpoint can have many wires connected
19#engageug
20. Fundamentals – msg.payload
• Node-RED nodes consume input messages and produce
output messages.
• Messages are JavaScript objects that contain at least a
“payload” parameter
msg = {
payload:”message payload”
};
20#engageug
21. Fundamentals – input nodes
• Inject: injects a message on clicking the button, or by
schedule.
• HTTP: acts as a basic web server
• Websocket
• MQTT
• TCP
• UDP
• Serial in
21#engageug
22. Fundamentals – output nodes
• The input nodes has a corresponding output node of
same type.
• Debug: used to catch and display messages.
22#engageug
23. Fundamentals – function node
• A function node uses the input message to produce one or
more output messages.
if (msg.payload === “Domino”) {
msg.payload = “You should visit Engage!”
} else {
msg.payload = “You should panic!”
}
return msg;
23#engageug
25. Fundamentals – some processing nodes
• Switch: easily route messages depending on properties of
the input.
• HTTP request: a request to an URL with the method you
choose (GET, PUT, etc).
• Change: configurable rules for manipulating message,
including search and replace.
• CSV: converting to and from CSV.
• JSON: converting to and from JSON.
• XML: converting to and from XML.
25#engageug
26. Fundamentals – catch node
• If you get an error in the flow it will simply halt. By adding
a catch node you can instead take care of the error and
then continue the flow from a suitable point.
26#engageug
27. Fundamentals – storage nodes
• The default set of storage nodes works with simple files,
like a CSV-file.
• Third party storage nodes
- mongodb
- mysql
- S3
- dropbox
- Box
27#engageug
28. Fundamentals – social and other nodes
• Twitter
• Slack
• Instagram
• Google Calendar
• Fitbit / Strava
• Weather
• Salesforce
• Domino
28#engageug
32. To get you started
https://cookbook.nodered.org/
http://noderedguide.com/
https://developer.ibm.com/blogs/top-5-reasons-to-use-node-
red-right-now/
https://www.youtube.com/user/stevecope/videos
32#engageug
34. Installation on Docker
• Container allows standard setup
• For Docker images, see
https://nodered.org/docs/platforms/docker
• Node.js v10 versions available now, see
https://github.com/node-red/node-red-docker#images
• Use Docker volumes to persist data
• Upgrade with docker pull nodered/node-red-
docker
34#engageug
35. Docker Useful Info
• Use docker cp to copy files into / out of container
• Container needs to be running to copy in / out
• Use volume to separate data from container
• Use –v SRC:DEST when creating container
• To bind to current folder for data use:
• ${pwd} (Linux and MacOS)
• %cd% Windows cmd prompt
• ${PWD} Windows Powershell
• Use docker network create and docker network
connect to link containers
• host.docker.internal is special DNS to host machine
35#engageug
36. Visual Studio Code Plugin
• Official Docker plugin for VS Code adds functionality
• Linting for Dockerfiles
• Easily see images, containers, registries
• Easily inspect images
• Easily create new container (run) with default options
• Easily see status of, start, stop and restart containers
• Easily attach shell to running containers
36#engageug
37. Projects
• New since 0.18
• Manages flow files, backed by Git repo
• Enabled in settings.js and needs git and ssh-keygen
• Encrypting credentials file with secret recommended
• Project stored in /.node-red/projects/project-name
• Each project has its own package.json with dependencies
37#engageug
39. Security
• Always secure Node-RED!
• Known malware attacks on unsecured
https://discourse.nodered.org/t/malware
-infecting-unsecured-node-red-servers/3460
• Enable adminAuth setting to restrict access to editor and
admin API
• Can define usernames and passwords or map to custom
JS authenticate function (e.g. → Domino)
• Enable TLS or use proxy (e.g. NGINX)
• Secure HTTP nodes accordingly
39#engageug
41. Configuration
• Use editorTheme in settings.js to customise editor
• Change titles, images, reference css files
• Amend settings.js also for
• Changing logging settings
• Modifying root paths
• Storing context variables elsewhere (e.g. Domino)
• Add nodes via Manage Palette
• Flows can be imported / exported
• Remember to “Deploy” to save / see changes!
41#engageug
43. Anatomy of a Node
• See https://nodered.org/docs/creating-nodes/
• Name and JS file referenced in package.json
• HTML file defines how it appears in editor. Three parts, each
wrapped in a <script> tag
• Node definition, how it appears in palette and editor event code
• RED.nodes.registerType name must map to JS file
• Edit dialog template, HTML the user interacts with
• Help text dialog, HTML that appears in info panel
• JavaScript file
• JS function for runtime action
• RED.nodes.registerType maps function to HTML file node’s name
43#engageug
44. Development and Testing
• Best to test against locally installed Node-RED instance
• See https://nodered.org/docs/creating-nodes/packaging
• Use npm link to create symbolic link between Node-
RED and the folder containing package.json
• Debug from VS Code using Launch Profile
• Debug > Add Configuration…, creates launch.json
• Then add debug point and VS Code will stop, allowing
debugging
44#engageug
47. Thank You
47#engageug
Paul Withers
Intec Systems Ltd & OpenNTF
pwithers@intec.co.uk
@paulswithers
https://www.intec.co.uk/blog
https://www.dominonextstep.com/
take-the-quiz/
Fredrik Malmborg
PSK Syd AB
fm@psksyd.com
@replikera