# Node-RED Function Node Patterns (EVOLV Summary) Based on: https://nodered.org/docs/user-guide/writing-functions ## Return Semantics - `return msg;` sends to output 1. - `return [msg1, msg2, ...];` sends one message per output position. - Use `null` for outputs that should not emit. Examples: - `return [msg, null, null];` -> output 1 only - `return [null, msg, null];` -> output 2 only ## Message Mutation Pattern - Start with the incoming `msg`, set fields (`msg.topic`, `msg.payload`), then return/send. - This preserves message context unless there is a deliberate reason to create a new object. ## Async Function Pattern - For asynchronous work, call `node.send(...)` and then `node.done()`. - Avoid returning a message when output is sent asynchronously. ## EVOLV Practical Rule - In example flows (including parsers), always align return-array position with downstream wiring. - For dashboard parser functions, keep one stable output mapping per metric to avoid wire-level regressions.