0% found this document useful (0 votes)
2 views

Node-RED_Creating your First Flow

This tutorial introduces users to creating their first flow in Node-RED, demonstrating the use of Inject, Debug, and Function nodes. It provides step-by-step instructions on accessing the editor, adding nodes, wiring them together, and deploying the flow. The final flow formats timestamps into readable strings using custom JavaScript in the Function node.

Uploaded by

Eva Suárez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Node-RED_Creating your First Flow

This tutorial introduces users to creating their first flow in Node-RED, demonstrating the use of Inject, Debug, and Function nodes. It provides step-by-step instructions on accessing the editor, adding nodes, wiring them together, and deploying the flow. The final flow formats timestamps into readable strings using custom JavaScript in the Function node.

Uploaded by

Eva Suárez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

13/3/23, 11:59 Creating your first flow : Node-RED

Node-RED

home
about
blog
documentation
forum
flows
github


docs • tutorials • first flow


Overview
1. Access the editor
2. Add an Inject node
3. Add a Debug node
4. Wire the two together
5. Deploy
6. Inject
7. Add a Function node
Summary
Source
Next Steps
Related reading

Creating your first flow


Overview

This tutorial introduces the Node-RED editor and creates a flow that demonstrates the Inject, Debug and Function nodes.

1. Access the editor

With Node-RED running, open the editor in a web browser.

If you are using a browser on the same computer that is running Node-RED, you can access it with the url: http://localhost:1880.

If you are using a browser on another computer, you will need to use the ip address of the computer running Node-RED: http://<ip-address>:1880.

2. Add an Inject node


The Inject node allows you to inject messages into a flow, either by clicking the button on the node, or setting a time interval between injects.

Drag one onto the workspace from the palette.

Select the newly added Inject node to see information about its properties and a description of what it does in the Information sidebar pane.

3. Add a Debug node

The Debug node causes any message to be displayed in the Debug sidebar. By default, it just displays the payload of the message, but it is possible to display the
entire message object.

4. Wire the two together


Connect the Inject and Debug nodes together by dragging between the output port of one to the input port of the other.

5. Deploy

At this point, the nodes only exist in the editor and must be deployed to the server.

Click the Deploy button.

6. Inject
With the Debug sidebar tab selected, click the Inject button (the small square button next to your inject node). You should see numbers appear in the sidebar. By
default, the Inject node uses the number of milliseconds since January 1st, 1970 as its payload.

7. Add a Function node

The Function node allows you to pass each message though a JavaScript function.

Delete the existing wire (select it and press delete on the keyboard).

Wire a Function node in between the Inject and Debug nodes.

Double-click on the Function node to bring up the edit dialog. Copy the following code into the function field:

// Create a Date object from the payload


var date = new Date(msg.payload);
// Change the payload to be a formatted Date string
https://nodered.org/docs/tutorials/first-flow 1/2
13/3/23, 11:59 Creating your first flow : Node-RED
msg.payload = date.toString();
// Return the message so it can be sent on
return msg;

Click Done to close the edit dialog and then click the deploy button.

Now when you click the Inject button, the messages in the sidebar will now be formatted is readable timestamps.

Summary
This flow demonstrates the basic concept of creating a flow. It shows how the Inject node can be used to manually trigger a flow, and how the Debug node displays
messages in the sidebar. It also shows how the Function node can be used to write custom JavaScript to run against messages.

Source

The flow created in this tutorial is represented by the following json. To import it into the editor, copy it to your clipboard and then paste it into the Import dialog.
[{"id":"58ffae9d.a7005","type":"debug","name":"","active":true,"complete":false,"x":640,"y":200,"wires":[]},{"id":"17626462.e89d9c","type":"inject","n

Next Steps
Create your second flow

Related reading

Using the editor


The Core nodes
Working with messages
Using the Function node

Node-RED: Low-code programming for event-driven applications.

GitHub
npm
Documentation
APIs

Flow Library
About
Code of Conduct
Community

Blog
Twitter
Forum
Slack
Mastodon

Copyright OpenJS Foundation and Node-RED contributors. All rights reserved. The OpenJS Foundation has registered trademarks and uses trademarks. For a list of
trademarks of the OpenJS Foundation, please see our Trademark Policy and Trademark List. Trademarks and logos not indicated on the list of OpenJS Foundation
trademarks are trademarks™ or registered® trademarks of their respective holders. Use of them does not imply any affiliation with or endorsement by them.

The OpenJS Foundation | Terms of Use | Privacy Policy | OpenJS Foundation Bylaws | Trademark Policy | Trademark List | Cookie Policy

https://nodered.org/docs/tutorials/first-flow 2/2

You might also like