Node-RED Loop Processing Nodes

0.5.1 · active · verified Wed Apr 22

This package provides three essential Node-RED nodes designed to facilitate flow looping within the Node-RED environment: `counter-loop`, `array-loop`, and `while-loop`. The `counter-loop` node enables `for-loop`-like behavior using a configurable counter, defining initial, terminal, and increment values. The `array-loop` node iterates over elements within a standard JavaScript array, akin to `forEach` or `for-of`, exposing the current key and value. The `while-loop` node executes based on a dynamic conditional expression. Currently at version 0.5.1, the package is actively maintained with a steady cadence of minor updates, frequently addressing bug fixes and introducing new features such as loop time limitations for `while-loop` and explicit variable resetting for iterative nodes. It significantly enhances Node-RED's capabilities by providing structured control flow mechanisms for repetitive tasks, which are not inherently available through basic core nodes.

Common errors

Warnings

Install

Quickstart

This quickstart JSON demonstrates how to install the package and configure a basic `counter-loop` node in Node-RED, iterating a counter from 0 to 5 and logging each step, while also showing the loop completion.

{
  "id": "e9a6e1a4.9c488",
  "type": "tab",
  "label": "Loop Processing Quickstart",
  "disabled": false,
  "info": "Quickstart for node-red-contrib-loop-processing\n\n1. **Install:** `npm install node-red-contrib-loop-processing` in your Node-RED user directory (~/.node-red), then restart Node-RED.\n2. **Drag & Drop:** Place an 'Inject' node, a 'counter-loop' node, and two 'Debug' nodes on the canvas.\n3. **Configure counter-loop:**\n   - Property: `msg.payload.counter`\n   - Initial value: `0`\n   - Terminal value: `5`\n   - Operator: `<=`\n   - Increment value: `1`\n   - Check 'Reset counter when loop exits'.\n4. **Connect:**\n   - Inject node -> counter-loop input\n   - counter-loop 'true' output -> Debug node (set to display `msg.payload.counter`)\n   - counter-loop 'false' output -> Debug node (set to display 'Loop Finished')\n5. **Deploy and Test:** Click the inject button to see the counter increment in the debug sidebar."
}

view raw JSON →