or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

application.mdcli.mdfunction-nodes.mdhttp-services.mdindex.mdnode-development.mdruntime.mdutilities.md
tile.json

tessl/npm-node-red

Low-code programming platform for event-driven applications with visual flow-based editor and runtime system

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/node-red@4.1.x

To install, run

npx @tessl/cli install tessl/npm-node-red@4.1.0

index.mddocs/

Node-RED

Node-RED is a low-code programming platform for event-driven applications that enables developers to create IoT applications, automation workflows, and data processing pipelines through a visual flow-based editor. It provides both a runtime system for executing flows and a complete development environment with drag-and-drop nodes, visual programming, and extensive extensibility.

Package Information

  • Package Name: node-red
  • Package Type: npm
  • Language: JavaScript/Node.js
  • Installation: npm install node-red
  • CLI Installation: npm install -g node-red

Core Imports

const RED = require("node-red");

ES Modules:

import RED from "node-red";

Basic Usage

const RED = require("node-red");
const express = require("express");
const http = require("http");

// Create Express app and HTTP server
const app = express();
const server = http.createServer(app);

// Initialize Node-RED
RED.init(server, {
    functionGlobalContext: {},
    userDir: "./node-red-data",
});

// Start Node-RED
RED.start().then(() => {
    console.log("Node-RED started");
    
    // Serve the editor on /red
    app.use("/red", RED.httpAdmin);
    
    // Serve HTTP nodes on /api
    app.use("/api", RED.httpNode);
    
    server.listen(3000, () => {
        console.log("Server running on port 3000");
        console.log("Editor available at http://localhost:3000/red");
    });
});

Architecture

Node-RED is built around several key components:

  • Main Module: Core application entry point with lifecycle management (init, start, stop)
  • Runtime System: Flow execution engine with node management and messaging system
  • Editor API: RESTful API and WebSocket interface for the browser-based flow editor
  • HTTP Services: Express applications for serving the editor and HTTP-based nodes
  • Node Registry: Dynamic loading and management of node types and modules
  • Context System: Persistent data storage across nodes, flows, and global scopes
  • Function Sandbox: Secure JavaScript execution environment for Function nodes

Capabilities

Application Lifecycle

Core application initialization and control for embedding Node-RED in other applications.

/**
 * Initialize the Node-RED application
 * @param httpServer - HTTP server instance (optional)
 * @param userSettings - Configuration settings object
 */
function init(httpServer?: http.Server, userSettings: UserSettings): void;

/**
 * Start the Node-RED runtime and editor
 * @returns Promise that resolves when startup is complete
 */
function start(): Promise<void>;

/**
 * Stop the Node-RED runtime and editor
 * @returns Promise that resolves when shutdown is complete
 */
function stop(): Promise<void>;

Application Management

Runtime API

Programmatic access to flow management, node operations, and runtime control for administrative applications.

/**
 * Runtime API for flow and node management
 */
interface RuntimeAPI {
    flows: FlowsAPI;
    nodes: NodesAPI;
    settings: SettingsAPI;
    library: LibraryAPI;
    context: ContextAPI;
    projects: ProjectsAPI;
    diagnostics: DiagnosticsAPI;
    plugins: PluginsAPI;
}

/**
 * Get current flow configuration
 * @param opts - Request options
 * @returns Promise resolving to flow configuration
 */
flows.getFlows(opts: RequestOptions): Promise<FlowConfig[]>;

/**
 * Set flow configuration
 * @param opts - Request options with flow data
 * @returns Promise resolving to deployment result
 */
flows.setFlows(opts: RequestOptions & { flows: FlowConfig[] }): Promise<DeploymentResult>;

Runtime Operations

Utility Functions

General-purpose utilities for message handling, logging, and Node-RED development.

/**
 * Logging system
 */
interface LoggingAPI {
    info(msg: any): void;
    warn(msg: any): void;
    error(msg: any): void;
    debug(msg: any): void;
    trace(msg: any): void;
    audit(event: AuditEvent, req?: http.IncomingMessage): void;
}

/**
 * General utilities for message manipulation
 */
interface UtilityAPI {
    generateId(length?: number): string;
    cloneMessage(msg: NodeMessage): NodeMessage;
    getMessageProperty(msg: NodeMessage, prop: string): any;
    setMessageProperty(msg: NodeMessage, prop: string, value: any, createMissing?: boolean): boolean;
    evaluateNodeProperty(value: any, type: string, node: NodeObject, msg: NodeMessage): any;
}

Utilities

Function Node Development

JavaScript execution environment and APIs available within Function nodes for custom logic implementation.

/**
 * Available in Function node context
 */
interface FunctionNodeContext {
    msg: NodeMessage;
    node: NodeInstance;
    context: ContextStore;
    flow: ContextStore;
    global: ContextStore;
    env: EnvironmentVariables;
    RED: NodeREDUtilities;
}

/**
 * Node instance methods available in Function nodes
 */
interface NodeInstance {
    send(msg: NodeMessage | NodeMessage[], clone?: boolean): void;
    error(err: string | Error, msg?: NodeMessage): void;
    warn(warning: string | object): void;
    log(info: string | object): void;
    status(status: NodeStatus | string | boolean | number): void;
}

Function Nodes

Node Development

APIs for creating custom node types and extending Node-RED functionality.

/**
 * Node registration function (available in node modules)
 */
interface NodeAPI {
    registerType(type: string, constructor: NodeConstructor): void;
    getNode(id: string): NodeInstance | null;
    createNode(node: NodeInstance, config: NodeConfig): void;
}

/**
 * Node constructor interface
 */
interface NodeConstructor {
    (this: NodeInstance, config: NodeConfig): void;
}

Node Development

HTTP Services

Express applications for building web interfaces and HTTP endpoints within Node-RED applications.

/**
 * Express application for editor interface
 */
const httpAdmin: express.Application;

/**
 * Express application for HTTP nodes
 */
const httpNode: express.Application;

/**
 * HTTP server instance
 */
const server: http.Server;

HTTP Integration

Command Line Interface

Command-line tools for running Node-RED server, managing node modules, and administrative operations.

# Start Node-RED server
node-red [options]

# Administrative commands
node-red admin <command> [options]

# Common options
-p, --port PORT        # Port to listen on (default: 1880)
-s, --settings FILE    # Settings file to use
-u, --userDir DIR      # User directory (default: ~/.node-red)
--safe                 # Enable safe mode (no flows loaded)
-v, --verbose          # Enable verbose output

Command Line Interface

Types

interface UserSettings {
    uiPort?: number;
    uiHost?: string;
    httpAdminRoot?: string;
    httpNodeRoot?: string;
    userDir?: string;
    flowFile?: string;
    credentialSecret?: string;
    httpNodeCors?: object;
    logging?: object;
    contextStorage?: object;
    functionGlobalContext?: object;
    exportGlobalContextKeys?: boolean;
    externalModules?: object;
}

interface NodeMessage {
    _msgid: string;
    topic?: string;
    payload: any;
    [key: string]: any;
}

interface FlowConfig {
    id: string;
    type: string;
    name?: string;
    disabled?: boolean;
    info?: string;
    [key: string]: any;
}

interface RequestOptions {
    user?: UserObject;
    req?: http.IncomingMessage;
}

interface NodeStatus {
    fill?: 'red' | 'green' | 'yellow' | 'blue' | 'grey';
    shape?: 'ring' | 'dot';
    text?: string;
}