Low-code programming platform for event-driven applications with visual flow-based editor and runtime system
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Core application lifecycle management for embedding Node-RED in other applications. These functions control the initialization, startup, and shutdown of the complete Node-RED system including runtime and editor components.
Initialize the Node-RED application with HTTP server and configuration settings.
/**
* Initialize the Node-RED application
* @param httpServer - Optional HTTP server instance. If not provided, settings object is first parameter
* @param userSettings - Configuration settings object
*/
function init(httpServer?: http.Server, userSettings: UserSettings): void;Usage Examples:
const RED = require("node-red");
const http = require("http");
// Option 1: With existing HTTP server
const server = http.createServer();
RED.init(server, {
userDir: "./node-red-data",
httpAdminRoot: "/admin",
httpNodeRoot: "/api"
});
// Option 2: With settings only (Node-RED manages server)
RED.init({
uiPort: 1880,
userDir: "./node-red-data"
});Start the Node-RED runtime and editor services. Must be called after init().
/**
* Start the Node-RED runtime and editor
* @returns Promise that resolves when startup is complete
*/
function start(): Promise<void>;Usage Examples:
RED.start().then(() => {
console.log("Node-RED started successfully");
}).catch(err => {
console.error("Failed to start Node-RED:", err);
});
// With async/await
try {
await RED.start();
console.log("Node-RED started");
} catch (err) {
console.error("Startup failed:", err);
}Stop the Node-RED runtime and editor. Should be called before process exit for clean shutdown.
/**
* Stop the Node-RED runtime and editor
* @returns Promise that resolves when shutdown is complete
*/
function stop(): Promise<void>;Usage Examples:
// Graceful shutdown
process.on('SIGINT', async () => {
console.log('Shutting down Node-RED...');
try {
await RED.stop();
console.log('Node-RED stopped');
process.exit(0);
} catch (err) {
console.error('Error during shutdown:', err);
process.exit(1);
}
});Access the Express applications for custom integration.
/**
* Express application for the editor interface
*/
const httpAdmin: express.Application;
/**
* Express application for HTTP nodes
*/
const httpNode: express.Application;
/**
* HTTP server instance used by Node-RED
*/
const server: http.Server;Usage Examples:
const express = require("express");
const app = express();
// Start Node-RED
await RED.start();
// Integrate editor into existing app
app.use("/red", RED.httpAdmin);
// Integrate HTTP nodes into existing app
app.use("/api", RED.httpNode);
// Add custom routes
app.get("/status", (req, res) => {
res.json({
version: RED.version,
uptime: process.uptime()
});
});Get the current Node-RED version.
/**
* Get the Node-RED version string
*/
const version: string;interface UserSettings {
/** Port for the editor UI (default: 1880) */
uiPort?: number;
/** Host for the editor UI (default: '0.0.0.0') */
uiHost?: string;
/** Root path for admin API (default: '/') */
httpAdminRoot?: string;
/** Root path for HTTP nodes (default: '/') */
httpNodeRoot?: string;
/** User directory for flows and settings (default: ~/.node-red) */
userDir?: string;
/** Flow file name (default: 'flows.json') */
flowFile?: string;
/** Secret for encrypting credentials */
credentialSecret?: string;
/** CORS settings for HTTP nodes */
httpNodeCors?: {
origin?: string | string[];
credentials?: boolean;
};
}interface AdvancedSettings {
/** Logging configuration */
logging?: {
console?: {
level: 'fatal' | 'error' | 'warn' | 'info' | 'debug' | 'trace';
metrics?: boolean;
audit?: boolean;
};
file?: {
level: string;
filename: string;
maxFiles?: number;
maxSize?: string;
};
};
/** Context storage configuration */
contextStorage?: {
default?: string;
stores?: {
[storeName: string]: {
module: string;
config?: object;
};
};
};
/** Global context for Function nodes */
functionGlobalContext?: object;
/** Export global context keys to Function nodes */
exportGlobalContextKeys?: boolean;
/** External modules configuration */
externalModules?: {
modules?: {
[moduleName: string]: {
module: string;
config?: object;
};
};
};
}Usage Examples:
RED.init({
uiPort: 1880,
userDir: "./node-red-data",
httpAdminRoot: "/admin",
httpNodeRoot: "/api",
flowFile: "flows.json",
credentialSecret: "my-secret-key",
functionGlobalContext: {
util: require("util"),
moment: require("moment")
},
logging: {
console: {
level: "info",
metrics: false,
audit: false
}
},
contextStorage: {
default: "memoryOnly",
stores: {
memoryOnly: { module: "memory" },
file: { module: "localfilesystem" }
}
}
});