可以将 Node-RED 嵌入到更大的应用程序中。一个典型的场景是,您使用 Node-RED 生成数据流,并希望在同一个应用程序的 Web 仪表板上显示这些数据流。
在您的应用程序的 package.json
中,将 node-red
添加到模块依赖项中,以及您可能拥有的任何单独的节点依赖项。
以下是将运行时嵌入到更广泛的 Express 应用程序中的最小示例。
var http = require('http');
var express = require("express");
var RED = require("node-red");
// Create an Express app
var app = express();
// Add a simple route for static content served from 'public'
app.use("/",express.static("public"));
// Create a server
var server = http.createServer(app);
// Create the settings object - see default settings.js file for other options
var settings = {
httpAdminRoot:"/red",
httpNodeRoot: "/api",
userDir:"/home/nol/.nodered/",
functionGlobalContext: { } // enables global context
};
// Initialise the runtime with a server and settings
RED.init(server,settings);
// Serve the editor UI from /red
app.use(settings.httpAdminRoot,RED.httpAdmin);
// Serve the http nodes UI from /api
app.use(settings.httpNodeRoot,RED.httpNode);
server.listen(8000);
// Start the runtime
RED.start();
当使用这种方法时,Node-RED 中包含的 settings.js
文件将不会被使用。相反,设置将传递给 RED.init
调用,如上所示。
此外,以下设置将被忽略,因为它们由您自行配置 Express 实例:
uiHost
uiPort
httpAdminAuth
httpNodeAuth
httpStatic
httpStaticAuth
https
版权所有 OpenJS Foundation 和 Node-RED 贡献者。保留所有权利。OpenJS Foundation 已注册商标并使用商标。有关 OpenJS Foundation 商标的列表,请参阅我们的商标政策和商标列表。未在OpenJS Foundation 商标列表上列出的商标和徽标是其各自持有者的商标™或注册®商标。使用它们并不意味着与它们有任何关联或得到它们的认可。
OpenJS Foundation | 使用条款 | 隐私政策 | OpenJS Foundation 章程 | 商标政策 | 商标列表 | Cookie 政策