Node-RED JavaScript Tutorial: Transform Messages Inside Function Nodes
Node-RED passes messages between connected nodes, and a Function node adds JavaScript transformation at a chosen point in that flow. Inspect the incoming message before changing its payload, then decide whether to forward it, route it, or stop propagation. Asynchronous operations and node context require deliberate lifetime and storage choices.
Here's a popular Node-RED JavaScript video — watch it, then summarize it with one click. Or paste any other YouTube link below.
— or paste your own YouTube link —
Want to keep the key points from a YouTube video? Paste the link below to turn it into structured notes.
Why Use Node-RED JavaScript Tutorial: Transform Messages Inside Function Nodes
- Inspect payloads without discarding message metadata
- Return messages through intended outputs
- Stop propagation with an explicit result
- Distinguish node context from message data
- Complete asynchronous processing appropriately
Frequently Asked Questions
Should a Function node replace the entire message just to change payload?
Replacing the object can discard metadata needed by later nodes. Modify or reconstruct it deliberately according to the flow's contract rather than assuming payload is the only meaningful property.
What does returning null communicate?
It prevents a message from being forwarded through that return path. Use it when stopping propagation is intentional, and distinguish it from an accidental missing return that makes a flow appear inactive.
How can one function route to several outputs?
Use the documented output representation so messages correspond to the intended output positions. A nested array shape has specific meaning, so inspect the contract instead of guessing from ordinary collection syntax.
Where should asynchronous results be sent?
Use the Function node's supported asynchronous messaging and completion mechanisms. A return that already finished cannot later deliver a callback result merely because the callback belongs to the same source function.
Does context data always survive a restart?
Persistence depends on the configured context store and lifecycle. Choose the appropriate storage behavior instead of assuming every value placed in context becomes durable application data automatically.