red-contrib-miniscule-transformer
v1.0.0
Published
TP2 IOT application - ISIMM
Readme
node-red-contrib-miniscule-transformer
A lightweight Node-RED node that lets you run a small JavaScript function as part of a flow.
This package contains the Node-RED node implementation files (node.js, node.html) and the package metadata (package.json). Use this node to execute custom JavaScript logic safely inside a Node-RED flow.
Features
- Add a configurable function to your Node-RED flows.
- Access
msg,flow, andglobalcontext from the function. - Return messages to downstream nodes using
returnornode.send(). - Small and easy to embed inside Node-RED.
Note: This node executes JavaScript code you provide. Be careful when running untrusted code — see the Security section.
Installation
From the Node-RED user directory (usually ~/.node-red):
# Install from npm (if published)
npm install node-red-contrib-miniscule-transformer
# Or install locally by copying this package directory into ~/.node-red/node_modules
# (useful during development)
# from this repo root:
npm link
# then in ~/.node-red
npm link node-red-contrib-miniscule-transformerAfter installation, restart Node-RED. The node will appear in the palette under a category named "taiponrock" (or similar based on the node.html configuration).
Usage
- Drag the TaiponRock node into a flow.
- Double-click to open the editor.
- Enter a JavaScript function body into the Function field. You can read and modify
msg. - Wire inputs and outputs as usual.
Example function body:
// simple example: add a timestamp and forward the message
msg.payload = msg.payload || {};
msg.payload.processedAt = new Date().toISOString();
return msg;Inside the function you can use:
msg— the message object.flow.get('key'),flow.set('key', value)— flow-scoped context.global.get('key'),global.set('key', value)— global context.node.warn(...),node.error(...)— to log from the node.
If you prefer asynchronous work, you can return null and use node.send() inside the function body if the implementation supports it (see node's editor help in the palette).
Example Flow
A minimal example flow that sends a string to the node and logs the output:
[
{
"id": "fa3b1f1b.000001",
"type": "inject",
"z": "flow1",
"name": "trigger",
"props": [{ "p": "payload" }],
"payload": "hello",
"payloadType": "str",
"repeat": "",
"crontab": "",
"once": true,
"onceDelay": 0.1,
"wires": [["taiponrock-node"]]
},
{
"id": "taiponrock-node",
"type": "taiponrock",
"z": "flow1",
"name": "process",
"func": "msg.payload = msg.payload + ' world';\nreturn msg;",
"outputs": 1,
"wires": [["debug1"]]
},
{
"id": "debug1",
"type": "debug",
"z": "flow1",
"name": "debug",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"wires": []
}
]Import this JSON into Node-RED (menu -> Import -> Clipboard) and deploy.
Configuration Options
The node editor exposes the following fields (names may vary depending on node.html):
- Name — optional node name shown in the flow.
- Function — the JavaScript code to execute. This should be a function body that operates on
msgand returnsmsg(or an array of messages for multiple outputs). - Outputs — how many outputs the node has.
Refer to the node.html source in this repository for the exact property names and UI elements.
Security
This node runs arbitrary JavaScript provided by the user. That means:
- Never paste or run code from untrusted sources.
- Do not use this node to process messages that originate from untrusted users or external inputs without validation.
- Avoid importing native modules or calling external processes from inside the function unless you control the function content.
If you need sandboxing or strict security guarantees, consider using Node-RED's built-in Function node or a dedicated sandboxing solution.
Development
The repository contains these important files:
node.js— node runtime implementation.node.html— node editor UI and configuration used by Node-RED.package.json— package metadata and dependencies.
To develop locally:
# from the project root
npm install
npm link
# in your Node-RED userDir (~/.node-red)
npm link node-red-contrib-miniscule-transformer
# restart Node-RED and test your nodeRun any available tests or linters you add to the package — none are included by default.
Publishing
If you plan to publish to npm:
- Update
package.jsonwith a unique package name (e.g.node-red-contrib-miniscule-transformer). - Ensure
keywordscontainsnode-redandnode-red-nodeto improve discoverability. - Run
npm publishfrom the repository root (you must be logged in withnpm login).
Refer to the Node-RED documentation for publishing nodes: https://nodered.org/docs/creating-nodes/packaging
Troubleshooting
- Node does not appear: make sure you installed the package into your Node-RED user directory (
~/.node-red/node_modules) and restarted Node-RED. - Errors in the function: check the Node-RED log (console) for stack traces. Use
node.warn()inside your function to debug.
Contributing
Contributions welcome. Open an issue or submit a PR with clear changes and tests if possible.
License
See the LICENSE file in this repository for license details.
If you'd like, I can also:
- Generate a short example flow file in the repo (JSON) you can import into Node-RED.
- Add a quick developer script to watch and reload the node in a local Node-RED instance.
Tell me which of those you'd like and I'll add it.
