Learn the basics of Node-RED: from installation to creating flows, working with nodes, and building interactive dashboards.
Node-RED is a flow-based development tool for visual programming, primarily used for wiring together hardware devices, APIs, and online services. It is built on Node.js and provides a browser-based editor for creating flows.
To install Node-RED, you need to have Node.js installed on your system. Follow these steps:
npm install -g node-red
node-red
Flows are the core of Node-RED. They consist of nodes connected together to define a sequence of operations. Here's how to create a simple flow:
Example: Create a flow that injects a timestamp and logs it to the debug panel.
1. Drag an "inject" node onto the workspace.
2. Drag a "debug" node onto the workspace.
3. Connect the "inject" node to the "debug" node.
4. Deploy the flow and click the inject node to see the timestamp in the debug panel.
Nodes are the building blocks of Node-RED. They can perform various tasks, such as injecting data, processing data, or outputting data. Here are some common nodes:
Example: Use a Function node to modify a message payload.
1. Drag an "inject" node onto the workspace.
2. Drag a "function" node onto the workspace.
3. Drag a "debug" node onto the workspace.
4. Connect the nodes in sequence: inject → function → debug.
5. Double-click the function node and add the following code:
msg.payload = "Hello, " + msg.payload;
6. Deploy the flow and click the inject node to see the modified message in the debug panel.
Node-RED provides a dashboard module to create interactive user interfaces. Follow these steps to build a simple dashboard:
npm install node-red-dashboard
Example: Create a dashboard with a button and a gauge.
1. Drag a "button" node from the dashboard palette onto the workspace.
2. Drag a "function" node onto the workspace.
3. Double-click the function node and add the following code:
4. Drag a "gauge" node from the dashboard palette onto the workspace.
5. Connect the nodes in sequence: button → function → gauge.
6. Deploy the flow and open the dashboard UI.
7. Access the dashboard by navigating to http://localhost:1880/ui.
8. Click the button to see the gauge update.
