Development

Creating a new Flow

Requirements

  • Determine the category of the flow and create a corresponding new grouping (ensure consistent coloring).
  • Add a comment with flow title and description/Readme at the top left of the grouping.
  • Clear arrays and objects in flow variables at the end of a flow.
  • Name nodes meaningfully.
  • remove debug logs

Best Practices

Config

Place a "set config" Node at the beginning and add your constants configurations to msg.config.

Use the STAGE Enviroment Variable to check if the system is in local/staging/production mode.

msg.config = {
  apiFilter: {...},
  filepath: env.get("STAGE") === "production" ? "/prod/path" : "/test/path",
  bucket: env.get("S3_STORAGE_BUCKET") || "test-bucket-fallback"
}

Functions and Logic

Define logic in advance in a "set functions" Node to set helper functions to messsage variables.

const items = [];
msg.addItem = (item) => items.push(item)
msg.getItems = () => items

Now we can use msg.addItem() later on in a loop without having to concatenate a Flow variable.

Loops

items.forEach(item => {
  msg.payload = item;
  node.send(msg);
})

When sending many Messages to make API requests use a Delay Node in rate limiter mode and set it to ~20msg/s

Wait for the end of a loop using a Trigger Node but make sure

  • to use at least 10s when waiting for API requests.
  • to extend the delay when a new message is received.

Implement complex loops with message limiter and continue variable. Useful when making several different API requests with the same Node.

Create complex loop

System Integrations

Akeneo

Working with Akeneo can be done using the installed akeneo-request Node.

Make sure to configure the correct endpoint:

  • Akeneo READ when fetching data.
  • Akeneo WRITE when creating, updating or deleting data.

This ensures correct data monitoring on Akeneo's side.

Shopware

Use the link out Node to send large amounts of requests like product updates to the Shopware Queue Tab/Flow.

However there is a shopware-request Node you can use to make simple API request.

The Message data structure is the same for both usages.

AWS

For each AWS Service there is a dedicated Node.

Each Node gets its parameter directly from the Message starting with a capital letter.

Ex.: msg.Bucket, msg.Body, msg.Key

Check for further information: https://github.com/daniel-t/node-red-contrib-aws

Slack

Of course Slack Nodes exist but there is also a Send messages to slack Flow you can use to send simple preformatted ERROR/WARNING/INFO Messages.

https://github.com/travisghansen/node-red-slack


Git(hub)

Files

Files to commit:

  • /data/flows/*
  • flow-manager-nodes-order.json
  • /modules/* (when working with modules)

Files to be careful with:

/data/config-nodes.yaml: Contains global config profiles like the Akeneo READ/Akeneo WRITE though it does not contain sensitive data like tokens and passwords. Profiles usually contain the ${ENV_VAR} syntax since these values are defined during deployment.

/data/flows_cred.json: This file contains all sensitive data and is encrypted using the CREDENTIALS_SECRET (settings.js). When in local development this secret is likely not set, so the file is not encrypted. NEVER commit this file unencrypted.

If you really want to edit this file, get the deployment secret and set it locally. Before committing you should decrypt the file manually and validate your changes since you could change other values unknowingly.

https://github.com/ambimax/nodered-decrypt-credentials

Pull request and conflicts

When reviewing a NodeRed pull request there is an inconvenience which causes a file to have changes is almost every line. This is cause by NodeRed generating new Node IDs.

Conflicts in the flow-manager-nodes-order.json are very likely when working with multiple branches. To fix:

  1. Export your made changes in NodeRed (⌘+E).
  2. Reset to the pull requests latest commit.
  3. Import your changes again (⌘+I).