Low-code programming platform for event-driven applications with visual flow-based editor and runtime system
npx @tessl/cli install tessl/npm-node-red@4.1.0Node-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.
npm install node-rednpm install -g node-redconst RED = require("node-red");ES Modules:
import RED from "node-red";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");
});
});Node-RED is built around several key components:
init, start, stop)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>;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>;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;
}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;
}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;
}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;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 outputinterface 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;
}