CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-node-red--nodes

Core nodes collection for Node-RED runtime providing fundamental building blocks for visual programming flows

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

function-nodes.mddocs/

Function Nodes

Function nodes provide data processing, transformation, and custom logic execution capabilities. These nodes enable complex data manipulation, conditional routing, and custom JavaScript code execution within Node-RED flows.

Capabilities

Function Node

Execute custom JavaScript code with access to Node-RED utilities and optional external npm modules. Supports sandboxed execution with full message processing capabilities.

/**
 * Function node for custom JavaScript execution
 * Registers as node type: "function"
 */
function FunctionNode(config) {
    RED.nodes.createNode(this, config);
    
    // Configuration properties:
    // config.func - JavaScript function code
    // config.outputs - Number of outputs (default 1)
    // config.libs - Array of external libraries/modules
    // config.timeout - Execution timeout in seconds
}

Usage Examples:

// Function node configuration with external modules
{
    "id": "function1",
    "type": "function",
    "func": "// Access external modules\nconst moment = global.get('moment');\n\nmsg.timestamp = moment().format();\nreturn msg;",
    "outputs": 1,
    "libs": [
        {
            "var": "moment",
            "module": "moment"
        }
    ],
    "timeout": 30
}

// Multi-output function
{
    "func": "if (msg.payload > 100) {\n    return [msg, null];\n} else {\n    return [null, msg];\n}",
    "outputs": 2
}

Switch Node

Route messages based on conditional rules. Supports multiple routing conditions with various comparison operators.

/**
 * Switch node for conditional message routing
 * Registers as node type: "switch"
 */
function SwitchNode(config) {
    RED.nodes.createNode(this, config);
    
    // Configuration properties:
    // config.property - Property to test (e.g., "payload", "topic")
    // config.rules - Array of routing rules
    // config.checkall - Check all rules or stop at first match
    // config.repair - Repair message sequence
}

// Rule structure for switch conditions
interface SwitchRule {
    t: string;      // Rule type: "eq", "neq", "lt", "lte", "gt", "gte", "btwn", "cont", "regex", etc.
    v: any;         // Value to compare against
    vt: string;     // Value type: "str", "num", "bool", "json", "msg", "flow", "global"
    v2?: any;       // Second value for between operations
    v2t?: string;   // Second value type
}

Usage Examples:

// Switch based on payload value
{
    "property": "payload",
    "rules": [
        {"t": "gt", "v": "100", "vt": "num"},
        {"t": "btwn", "v": "50", "vt": "num", "v2": "100", "v2t": "num"},
        {"t": "lt", "v": "50", "vt": "num"}
    ],
    "checkall": false,
    "repair": false
}

// Switch based on message topic
{
    "property": "topic",
    "rules": [
        {"t": "eq", "v": "temperature", "vt": "str"},
        {"t": "eq", "v": "humidity", "vt": "str"},
        {"t": "regex", "v": "sensor.*", "vt": "str"}
    ]
}

Change Node

Modify message properties with set, change, delete, and move operations. Supports JSONata expressions and various data types.

/**
 * Change node for modifying message properties
 * Registers as node type: "change"
 */
function ChangeNode(config) {
    RED.nodes.createNode(this, config);
    
    // Configuration properties:
    // config.rules - Array of change operations
}

// Change rule structure
interface ChangeRule {
    t: string;      // Rule type: "set", "change", "delete", "move"
    p: string;      // Property path to modify
    pt: string;     // Property type: "msg", "flow", "global"
    to?: any;       // Target value (for set/change)
    tot?: string;   // Target value type
    from?: any;     // Source value (for change operations)
    fromt?: string; // Source value type
}

Usage Examples:

// Set and modify properties
{
    "rules": [
        {
            "t": "set",
            "p": "payload.timestamp", 
            "pt": "msg",
            "to": "",
            "tot": "date"
        },
        {
            "t": "change",
            "p": "payload.status",
            "pt": "msg", 
            "from": "active",
            "fromt": "str",
            "to": "enabled",
            "tot": "str"
        },
        {
            "t": "delete",
            "p": "payload.temp",
            "pt": "msg"
        }
    ]
}

Range Node

Map numeric values between input and output ranges with scaling and rounding options.

/**
 * Range node for numeric value mapping
 * Registers as node type: "range"
 */
function RangeNode(config) {
    RED.nodes.createNode(this, config);
    
    // Configuration properties:
    // config.minin - Input minimum value
    // config.maxin - Input maximum value  
    // config.minout - Output minimum value
    // config.maxout - Output maximum value
    // config.action - Action for out-of-range values ("scale", "clamp", "drop")
    // config.round - Round output values
}

Usage Examples:

// Scale sensor values (0-1023) to percentage (0-100)
{
    "minin": "0",
    "maxin": "1023", 
    "minout": "0",
    "maxout": "100",
    "action": "scale",
    "round": true
}

// Convert temperature scales
{
    "minin": "0",
    "maxin": "100",
    "minout": "32", 
    "maxout": "212",
    "action": "clamp"
}

Template Node

Generate text using Mustache templating with access to message and context data.

/**
 * Template node for text generation using Mustache templates
 * Registers as node type: "template"
 */
function TemplateNode(config) {
    RED.nodes.createNode(this, config);
    
    // Configuration properties:
    // config.template - Mustache template string
    // config.field - Target field for output (default: "payload")
    // config.fieldType - Field type: "msg", "flow", "global"
    // config.format - Template format: "handlebars", "mustache", "plain"
    // config.syntax - Template syntax: "mustache", "plain"
    // config.output - Output format: "str", "json"
}

Usage Examples:

// Email template
{
    "template": "Hello {{payload.name}},\n\nYour order #{{payload.orderId}} has been {{payload.status}}.\n\nThank you!",
    "field": "payload",
    "format": "mustache",
    "output": "str"
}

// JSON template
{
    "template": "{\n  \"user\": \"{{payload.username}}\",\n  \"timestamp\": \"{{timestamp}}\",\n  \"value\": {{payload.value}}\n}",
    "output": "json"
}

Delay Node

Delay, throttle, or limit message rate with various timing options.

/**
 * Delay node for message timing control
 * Registers as node type: "delay"
 */
function DelayNode(config) {
    RED.nodes.createNode(this, config);
    
    // Configuration properties:
    // config.pauseType - Type: "delay", "delayv", "random", "rate", "queue"
    // config.timeout - Delay time in specified units
    // config.timeoutUnits - Time units: "milliseconds", "seconds", "minutes", "hours"
    // config.rate - Rate limit (messages per time period)
    // config.nbRateUnits - Number of time units for rate
    // config.rateUnits - Rate time units
    // config.randomFirst - Random delay minimum
    // config.randomLast - Random delay maximum
    // config.randomUnits - Random delay units
    // config.drop - Drop messages when rate limited
}

Usage Examples:

// Fixed delay
{
    "pauseType": "delay",
    "timeout": "5",
    "timeoutUnits": "seconds"
}

// Rate limiting
{
    "pauseType": "rate", 
    "rate": "10",
    "nbRateUnits": "1",
    "rateUnits": "second",
    "drop": true
}

// Random delay
{
    "pauseType": "random",
    "randomFirst": "1",
    "randomLast": "5", 
    "randomUnits": "seconds"
}

Trigger Node

Send messages after delays or conditions with retriggering support.

/**
 * Trigger node for conditional message sending with delays
 * Registers as node type: "trigger"
 */
function TriggerNode(config) {
    RED.nodes.createNode(this, config);
    
    // Configuration properties:
    // config.op1 - First output payload
    // config.op2 - Second output payload  
    // config.op1type - First payload type
    // config.op2type - Second payload type
    // config.duration - Delay duration
    // config.units - Duration units
    // config.extend - Extend delay on retrigger
    // config.reset - Reset payload
    // config.resetType - Reset payload type
}

Exec Node

Execute system commands with configurable arguments, working directory, and timeout.

/**
 * Exec node for executing system commands
 * Registers as node type: "exec"
 */
function ExecNode(config) {
    RED.nodes.createNode(this, config);
    
    // Configuration properties:
    // config.command - Command to execute
    // config.addpay - Append payload to command
    // config.append - Additional arguments  
    // config.useSpawn - Use spawn instead of exec
    // config.timer - Timeout in seconds
    // config.winHide - Hide window on Windows
    // config.oldrc - Use old return code behavior
}

RBE Node

Report By Exception - filter messages that haven't changed based on specified properties.

/**
 * RBE (Report By Exception) node for filtering unchanged values
 * Registers as node type: "rbe"
 */
function RBENode(config) {
    RED.nodes.createNode(this, config);
    
    // Configuration properties:
    // config.func - Function type: "rbe", "deadband", "narrowband"
    // config.gap - Deadband gap value
    // config.start - Start value for deadband
    // config.inout - Input/output property name
}

Message Processing Patterns

Function nodes follow standard Node-RED message processing:

// Standard input handler for function nodes
this.on("input", function(msg, send, done) {
    try {
        // Process based on node type
        var result = processMessage(msg, config);
        
        // Send result(s)
        if (Array.isArray(result)) {
            send(result); // Multiple outputs
        } else {
            send(result); // Single output
        }
        
        done();
    } catch (error) {
        done(error);
    }
});

// Multi-output handling
function handleMultipleOutputs(msg) {
    // Return array with one element per output
    // null elements indicate no message for that output
    return [msg1, null, msg3]; // Send to outputs 1 and 3 only
}

docs

common-nodes.md

function-nodes.md

index.md

network-nodes.md

parser-nodes.md

sequence-nodes.md

storage-nodes.md

tile.json