Beginners Guide to Node-Red Flows

A flow is a collection of nodes wired together and appears as a tab in the workspace.

Flows are the main way of organising nodes.

A flow has a context variable associated with it which is available to all nodes in the flow. See Understanding node-red context variables



A Basic Flow

You can wire the inject node into the debug node to create a basic flow as shown below.

Basic-Flow-node-red

The above flow will inject a unix timestamp into the debug node which can be viewed in the debug tab in the far right pane.

Deploying Flows

When you start node red then all currently enabled flows are automatically started.

If you edit or create a new flow you will need to deploy it using the deploy button.

The Deploy button on the top right change from grey to maroon when changes have been made to a flow to indicate that in it needs to be deployed.

node-red-deploy

You can choose to deploy all flows in the workspace, modified flows,modified nodes or restart flows.

See Deploying Node-Red Flows

Working With Flows

The workspace consists of all of your flows.

Along the top of the workspace pane are tabs that are used to open previously created flows.

You can create new Flows by clicking on the Plus button on the top right.

create-new-flow

When you create a new empty Flow it is given a default name and is enabled by default.

Generally you create a new flow when the flow needs to do a distinct task.

To add nodes to a flow drag them from the node palette on the left into the active flow in the middle pane.

You can link the nodes together by dragging a wire between them.

A collection of linked nodes is called a flow.

Note: All flows in the workspace share the same node.js event loop.

How to Hide,Rename,Disable and Delete  Flows

A flow called Flow1 is pretty meaningless and so you should rename it to something more meaningful.

You can access the flow properties from the settings tab or by double clicking on the flow name.

You need to select the flow in the workspace and then to open the flow go to the menu (top right) node-menu and select flows> rename flow, delete, add. node-delete-flow

If you select rename then a window opens that displays the flow properties .

You can rename the flow, and there is also a toggle to enable/disable it..

There is also a delete button to delete the flow on the top left.

enable-disable-flow-node-red

You then need to redeploy for the setting to take effect.

You can also access this setting by double clicking on the flow name tab:

disable-node-red-flow

You should notice the icon in the flow tab that indicates that the flow is disabled.

You can also change the order of the flows in the workspace by clicking on the flow tab and dragging it left or right.

In node-red version 2.1 the ability to hide flows was also added which is useful if you have lots of flows in the workspace.

To view all flows after they have been hidden you can use the tab menu as shown in the screen shot below

hide-flows-tab-menu

Run time settings

Things like user editor settings and flow nodes are stored in the .config.json file pre node-red v1.2.

Note that this is a hidden file.

From 1.2 this is spit into 4 files

  • .config.nodes.json – the node registry
  • .config.users.json – user specific settings (eg editor settings)
  • .config.projects.json – project settings, including the active project
  • .config.runtime.json – everything else – most notable _credentialSecret

Note: above was copied from the documentation however on my installation I didn’t see the .config.projects.json file presumably because I am not using the project feature.

However i did have a.config.modules.json which isn’t mentioned in the documentation as far as I can see.

Flow Files -Storage and Backup

flows-backup-storageFlows that you create are stored by default in the .node-red directory of your home folder in a file called flows_servername.json.

The file is created when you run node-red for the first time, and is loaded each time that you run node-red.

EG. for my raspberry pi the file is flows_raspberrypi.json.

The file will contain all of the flows in the workspace.

However it is not the only file that is created. You will also see these files.

  • flows_raspberrypi.json.backup
  • flows_raspberrypi_cred.json.
  • flows_raspberrypi_cred.json.backup

flows_raspberrypi.json.backup – This is a backup of the flows_raspberrypi.json file, and functions like a word backup.

When you do a deploy the old flows_raspberrypi.json file is moved to the backup file and the flows_raspberrypi.json is overwritten.

 

This means that you can recover from a mistake if you notice it after 1 deploy by using the flows_raspberrypi.json.backup file.

flows_raspberrypi_cred.json. – This file contains login data used by some nodes. If it is not present the flows will still work, but you will need to add the information back in to any nodes that need it.

flows_raspberrypi_cred.json.backup – Backup of flows_raspberrypi_cred.json and functions the same way as the other backup.

Flow Backup

It is a good idea to backup your flows files on a regular basis. The automatic backup should only be considered a temporary one.

To do a complete backup then make a copy of the four files mentioned above:

  • flows_raspberrypi.json
  • flows_raspberrypi.json.backup.
  • flows_raspberrypi_cred.json.
  • flows_raspberrypi_cred.json.backup.

and also settings.js and other settings files

Note: you will need to change the names to match your flows files. my understanding is that you don’t need to backup the .config files but it doesn’t really take much more space.

Because they are all JSON files I just backup *.json and *.js.

Node-Red Backup

Because all of the flows and settings files are store in the .node-red folder creating a backup of this folder gives you a complete backup of node-red.

You should make sure that you store any data in a folder outside of .node-red.

Moving Your Flows to Another Machine

You can copy all of the flows by copying the flows_newmachinebane.json. file.

To use them on another machine change the file name to flows_newmachinebane.json.

The only file you really need is the flows_raspberrypi.json file however you should also copy the flows_raspberrypi_cred.json file.

See this github page for other important files and folders.

Creating Additional and Multiple Flow Files

You can created additional flow files for storing different workspaces.

To use another flows file you can create a new settings file and edit it.

As an example if I wanted to create a separate flows file to store client flows I would :

  • copy the old settings file to a new one called client_settings.js
  • Edit the settings file to point to the new flows file and remove the two forward slashes.

// flowFile: clientflows.json’,

  • Start node-red using
node-red -s client_settings.js

You could also use the new flows file without creating a new settings file by using the command option which is my preferred option.

node-red clientflows.json

The default settings file will be used.

Notice you don’t need a switch. See Local Installs and managing node-red projects for more details.

Debugging Flows

A flow debugger is available for node-red v2.

This is a node that you need to install and activate. Once activated you can set breakpoints in the flow and the flow will pause at the breakpoints.

A screen shot is shown below:

flow-debugger-node

You can find more details here

Stopping and Starting Flows

If you are having problems starting node-red due to a mistake in a flow then you can start node-red using the safe mode.

node-red –safe

In node-red version 3 the ability to stop and start flows has been added to the editor.

Currently it is not enabled by default. To enable it you need to edit the settings.js file and add the following

runtimeState: {
   enabled: true,
   ui: true
}

A new option appears on the deploy options drop down.

stop-start-flows

Note: All flows are stopped and not individual flows

<===== Node-Red Editor

=====> Deploying Node-red flows



Related Tutorials and Resources:

Click to rate this post!
[Total: 3 Average: 5]

7 comments

  1. Best greetings to your wife from Germany. I live near Nürnberg :).

    If I understand the text, than it is no real problem, if I don’t do any action, but if I have to do a full restore or want to transfer my Node-Red to another machine, than I need to input all credential again. Otherwise they are stored inside flows_cred.json.

    My nodes are: MQTT, Tasmota and Openweathermap.

  2. That’s great to here Steve, so send her nice greetings from Germany.

    I use MQTT, Openweathermap and Tasmota with credentials.

    If I understand the text, than it is no real problem, if I don’t any action, but if I have to do a full restore or want to transfer my Mode-Red to another machine, than I need to input all credential again. Otherwise they are stored inside flows_cred.json.

  3. Oh, that’s great. Best greetings to your wife!
    MQTT, Tasmota and eMail. If I understand it right, it is not a problem not to change it, but if I transfer to an other Raspi, or need a full restore, than I have to input the credentials new to this nodes, if I don’t have a personal key/password, or whatever.

    1. Then it is probably just missing the flowname_cred.json file as the password for some of the nodes are store in there and so you need to export that file as well.
      Rgds
      Steve

  4. Hi Steve, thanks for your well instructions. I’m searching around in Node-Red-Docs, forum, google, and your pages. But I can’t find a further explanation and example for my credentialSecret problem”

    Startind Node-Red I got:
    Sep 9 09:46:26 raspberrypi Node-RED[239]: Die Datei mit den Flow-Credentials wird mit einem vom System
    Sep 9 09:46:26 raspberrypi Node-RED[239]: generierten Schlüssel verschlüsselt.
    Sep 9 09:46:26 raspberrypi Node-RED[239]: Wenn der vom System generierte Schlüssel aus irgendeinem Grund
    Sep 9 09:46:26 raspberrypi Node-RED[239]: verloren geht, kann die Datei mit den Credentials nicht
    Sep 9 09:46:26 raspberrypi Node-RED[239]: wiederhergestellt werden. Sie muss dann gelöscht und die
    Sep 9 09:46:26 raspberrypi Node-RED[239]: Credentials müssen erneut eingestellt werden.
    Sep 9 09:46:26 raspberrypi Node-RED[239]: Es sollte ein eigener Schlüssel mit Hilfe der Option
    Sep 9 09:46:26 raspberrypi Node-RED[239]: ‘credentialSecret’ in der Einstellungsdatei vorgegeben werden.
    Sep 9 09:46:26 raspberrypi Node-RED[239]: Node-RED wird dann die Datei mit den Flow-Credentials
    Sep 9 09:46:26 raspberrypi Node-RED[239]: bei der nächsten Übernahme (deploy) einer Änderung erneut
    Sep 9 09:46:26 raspberrypi Node-RED[239]: verschlüsseln.

    Sorry, that it is in german, but the main sentence is the advice to define a key with ‘credentialSecret’. I found out, that it is for encryption node-credentials.

    But I don’t know where and how to do this!?

Leave a Reply

Your email address will not be published. Required fields are marked *