node-red-function-sync
v2.0.1
Published
Tooling for developing Node-RED function nodes locally using standard JavaScript workflows.
Maintainers
Readme
Node-RED Function Sync 🛠️
A collection of Node.js scripts to help professionalize Node-RED development by enabling local editing, testing, and synchronization of function nodes.
Features
- Extract to Local: Extract internal Node-RED function nodes to local
.jsfiles, organized by tab/subflow. - Bi-Directional Sync: Edit
.jsfiles locally and sync them back toflows.json, including tab movements. - JSDoc Metadata: Uses standard JavaScript JSDoc tags for metadata (ID, Name, Container).
- Complexity Scanner: Scan your
flows.jsonto identify complex function nodes that should be externalized and tested. - Testability: Automatically wraps function bodies in a testable
module.exports = function(...)wrapper.
Installation
Install via npm to use the CLI tools:
npm install --save-dev node-red-function-syncUsage
1. Extracting Function Nodes (nr-extract)
Used to scan for candidates or extract a specific node by its ID.
# Scan for complex candidates in flows.json
npx nr-extract --scan
# Extract a specific node to the src directory
npx nr-extract <NODE_ID> --src ./src --flows ./flows.jsonOptions:
--flows <path>: Path to yourflows.json(Default:flows.json)--src <path>: Local directory to save scripts (Default:src)--scan: Analyze all function nodes and sort by complexity.
2. Synchronizing Changes (nr-sync)
Used to push local changes from your .js files back into the flows.json. If you move a file to a different tab folder locally, nr-sync will update the node's container in Node-RED.
npx nr-sync --src ./src --flows ./flows.jsonOptions:
--flows <path>: Path to yourflows.json(Default:flows.json)--src <path>: Local directory to scan for changes (Default:src)
3. Migrating to v2.0.0 (nr-migrate)
Version 2.0.0 introduced a new JSDoc-style metadata format. Use this tool to upgrade your existing extracted files.
npx nr-migrate --src ./srcThis will convert old JSON blocks into the new format:
/**
* @nr-id node_id
* @nr-name Node Name
* @nr-z tab_id
*/File Safety & Conventions
Both nr-sync and nr-migrate include safety checks to prevent accidental modification of non-script files:
- Whitelisted: Only files ending in
.jsor.tsare scanned. - Blacklisted: Any file containing
.spec.or.test.(e.g.,my-func.spec.js) is strictly ignored. - Validation:
nr-migrateonly processes files that contain the Node-RED wrapper (module.exports = function).
These rules ensure that your unit tests and other project files remain untouched during synchronization or migration.
Workflow Guide
- Extract: Use
npx nr-extract --scanto find nodes, thennpx nr-extract <ID>to pull them locally. - Edit: Open the generated file in
src/with your favorite IDE. - Sync: Run
npx nr-syncto update your Node-RED flows. - Deploy: Restart or reload Node-RED to apply the changes.
Development
To run the internal unit tests:
npm test