Reusable Node-RED flows with an explicit input API.
This package adds three nodes that let you define a reusable flow once and call it from anywhere else in your workspace. Compared with plain subflows, the focus here is on a visible parameter contract, predictable return routing, and support for nested component calls.
Use components when you want to treat a flow like a callable unit with a defined interface:
- define a reusable flow with expected input parameters
- call that flow from another tab or branch with explicit parameter mapping
- return control to the caller through one or more return nodes
- keep nested component calls working without losing routing context
This is most useful when a project has many tabs or repeated orchestration logic and simple copy/paste or plain subflows are no longer enough.
Use this package when you need one or more of these properties:
- the called flow should expose a visible list of expected message inputs
- the caller should map values from msg, flow/global context, constants, environment variables, JSONata, or other node properties
- the called flow should be able to return through named return points
- nested component calls should preserve caller context
If you only need a simple reusable block with minimal configuration, standard Node-RED subflows may still be the simpler choice.
The currently validated support contract is:
- Node.js 18, 20, and 22
- Node-RED 4.x
The repository CI validates:
- runtime tests across the Node.js support matrix
- coverage and package-content checks
- browser-level editor workflows with headless Playwright
Install the package from the Node-RED palette manager or with npm:
npm install node-red-contrib-componentsAfter restarting Node-RED, the package contributes these palette nodes:
comp startcomp returnuse comp
comp start defines the entry point of a reusable component flow.
Use it to declare the component API:
- parameter name
- parameter type
- required or optional
That API is then picked up by use comp, which renders the parameter mapping UI for callers.
comp return hands the message back to the caller.
Key behavior:
- nested component calls are supported
- one component flow can contain multiple return nodes
- each return node can either feed the shared default output or expose its own labeled output on the caller
- if a return node receives a message outside a component call context, it can broadcast to matching callers for that flow
use comp calls a component defined elsewhere in the workspace.
For each declared parameter, the node can source values from the same kinds of inputs users know from the Change node and typed input controls, including:
msg, flow context, and global context- strings, numbers, booleans, JSON, timestamps, and other typed constants
- JSONata expressions
- environment variables
- node properties
Before dispatch, the node validates configured parameter values against the declared API and surfaces validation errors when required inputs are missing or types do not match.
The quickest way to understand the package is the shipped basic example.
- Open the Node-RED editor.
- Use Import.
- Select the examples for
node-red-contrib-components. - Import the
basic.jsonexample. - Deploy and trigger the inject node.
The basic example shows the smallest possible component round-trip:
- an inject node calls
use comp use comptargets a component defined bycomp start- the component returns through
comp return - the result appears in a debug node
- Add a
comp startnode and give the component a name. - Wire it to a
comp returnnode. - Add a
use compnode somewhere else in the flow. - Select the component in the
use compeditor. - If the component defines parameters, map each required input.
- Wire the caller output to a debug node.
- Trigger the caller with an inject node.
For more advanced setups, see the example flows listed below.
The runtime and editor behavior now align on these expectations:
- required parameters must be configured
- configured values are type-checked against the component API
- stale or missing target components are surfaced in the editor
- output label mismatches caused by changed return-node modes are surfaced in the editor
The package is usable, but there are still practical limits users should know about.
use comp can be copied on its own, but copying or cutting a whole component definition together with linked callers does not reliably preserve the association between the nodes.
If you need to move a component definition and its callers together, the safest workaround is:
- export the relevant nodes
- remove them from the original tab
- import them into the destination tab
The editor test suite covers a few high-value workflows, not every possible configuration path. Runtime behavior is covered primarily through Node-RED helper tests.
There are still feature ideas around richer parameter validation, output shaping, and additional parameter types. Treat those as future work, not as supported behavior in the current release.
The repository ships several example flows under examples/:
basic.json: minimal component round-tripembedded.json: nested component calls and multiple returnsbroadcast.json: return-node broadcast behaviorin-only.json: input-only component scenariosrecursion.json: recursive component wiring patterns
Repository commands:
npm test
npm run test:coverage
npm run pack:check
npm run uitest
npm run release:checkWhat they cover:
npm test: runtime regression suitenpm run test:coverage: runtime coverage with branch threshold enforcementnpm run pack:check: validates the published package contentsnpm run uitest: headless browser checks for key editor workflowsnpm run release:check: full release gate used for the current review hardening work
The repository distinguishes between stable releases and release candidates, but both are published through the same GitHub Actions workflow so npm Trusted Publishing can be bound to a single workflow file.
- Stable release tags use the format
vX.Y.Zand publish to the default npmlatestdist-tag. - Release candidate tags use the format
vX.Y.Z-rc.Nand publish to the npmnextdist-tag.
Typical maintainer flow:
# release candidate
npm version 0.4.0-rc.1
git push origin develop --follow-tags
# final release after RC validation
npm version 0.4.0
git push origin develop --follow-tagsThe GitHub Actions setup enforces that:
- only
vX.Y.ZandvX.Y.Z-rc.Ntags are accepted - release tags must point to a commit that is already contained in
master - both stable and RC publishes run the same validation gates before publishing
- RC publishes go to the npm
nextdist-tag and are marked as GitHub prereleases - stable publishes go to the default npm
latestdist-tag
Trusted Publishing setup on npm:
- In npm package settings for
node-red-contrib-components, configure one Trusted Publisher for GitHub Actions. - Use GitHub owner
ollixx, repositorynode-red-contrib-components, and workflow filenamenpm-publish.yml. - Keep
id-token: writeenabled in the workflow. - No npm publish token is required for
npm publishafter Trusted Publishing is configured.
For maintainers who need the runtime protocol details, see components/COMP_PROTOCOL.md.
The current focus is on a stable runtime, explicit compatibility targets, safer publishing, and a small but meaningful editor E2E suite. Feature ideas beyond that are better tracked as issues than kept inline in the package landing page.



