配置

以下属性可用于配置 Node-RED。

作为普通应用程序运行时,它从设置文件加载其配置。有关设置文件及其位置的更多信息,请阅读本指南

作为嵌入式应用程序运行时,配置选项在调用RED.init()时传递。但是,在此模式下运行时,某些属性将被忽略,并由嵌入式应用程序实现。

运行时配置

flowFile
用于存储流程的文件。默认值:flows_<hostname>.json
userDir
用于存储所有用户数据(例如流文件和凭据文件以及所有库数据)的目录。默认值:$HOME/.node-red
nodesDir
用于搜索其他已安装节点的目录。Node-RED 会在_userDir_目录下的nodes目录中搜索。此属性允许搜索额外的目录,以便可以将节点安装在 Node-RED 安装结构之外。默认值:$HOME/.node-red/nodes
uiHost
用于监听连接的接口。默认值:0.0.0.0 - 所有 IPv4 接口

仅限独立版.

uiPort
用于提供编辑器 UI 的端口。默认值:1880

仅限独立版.

httpAdminRoot
编辑器 UI 的根 URL。如果设置为false,则所有管理端点都将被禁用。这包括 API 端点和编辑器 UI。要仅禁用编辑器 UI,请参阅下面的disableEditor属性。默认值:/
httpAdminAuth
已弃用:请参阅adminAuth

在编辑器 UI 上启用 HTTP 基本身份验证

httpAdminAuth: {user:"nol", pass:"5f4dcc3b5aa765d61d8327deb882cf99"}

pass属性是实际密码的 md5 哈希值。以下命令可用于生成哈希值

node -e "console.log(require('crypto').createHash('md5').update('YOUR PASSWORD HERE','utf8').digest('hex'))"

仅限独立版.

httpAdminMiddleware
添加到所有管理路由的 HTTP 中间件函数或函数数组。中间件函数的格式记录在此处
httpAdminMiddleware: function(req,res,next) {
    // Perform any processing on the request.
    // Be sure to call next() if the request should be passed on
}
httpAdminCookieOptions
启用管理身份验证时,此项可用于自定义在设置用作 OAuth 身份验证流程一部分的会话 cookie 时使用的选项。可用选项记录在此处
httpNodeRoot
提供 HTTP 端点的节点的根 URL。如果设置为false,则所有基于节点的 HTTP 端点都将被禁用。默认值:/
httpNodeAuth
启用 HTTP 基本身份验证。有关格式,请参阅httpAdminAuth
httpRoot
此项设置管理和节点端点的根 URL。它会覆盖由httpAdminRoothttpNodeRoot设置的值。
https
启用 HTTPS,使用指定的选项对象,定义在此处

仅限独立版.

disableEditor
如果设置为true,则阻止运行时提供编辑器 UI。管理 API 端点保持活动状态。默认值:false
httpStatic
用于提供静态 Web 内容的本地目录。此内容从顶层 URL /提供。使用此属性时,httpAdminRoot也必须用于使编辑器 UI 在/以外的路径上可用。

此属性也可以设置为数组以支持多个静态目录,每个目录都有自己的一组选项。选项包括本地目录的路径以提供内容,提供它们的根 URL,可选的自定义中间件函数和可选的 CORS 配置。

例如

httpStatic: [
  {
      path: '/opt/static/',
      root: '/private/',
      middleware: myCustomHttpMiddleware,
      cors: {

      }
  }
]

仅限独立版.

httpStaticAuth
在静态内容上启用 HTTP 基本身份验证。有关格式,请参阅httpAdminAuth
httpStaticCors
为 httpStatic 端点启用跨域资源共享,定义在此处
httpNodeCors
为提供 HTTP 端点的节点启用跨域资源共享,定义在此处
httpNodeMiddleware
添加到所有 HTTP In 节点的 HTTP 中间件函数或函数数组。这允许对节点进行任何自定义处理,例如身份验证。中间件函数的格式记录在此处
httpNodeMiddleware: function(req,res,next) {
    // Perform any processing on the request.
    // Be sure to call next() if the request should be passed
    // to the relevant HTTP In node.
}
logging
目前只支持控制台日志记录。可以指定不同级别的日志记录。选项有
  • fatal - 只应记录使应用程序无法使用的错误
  • error - 记录被认为对特定请求致命的错误 + 致命错误
  • warn - 记录非致命问题 + 错误 + 致命错误
  • info - 记录有关应用程序一般运行的信息 + 警告 + 错误 + 致命错误
  • debug - 记录比信息更详细的信息 + 信息 + 警告 + 错误 + 致命错误
  • trace - 记录非常详细的日志记录 + 调试 + 信息 + 警告 + 错误 + 致命错误

默认级别是info。对于闪存存储有限的嵌入式设备,您可能希望将其设置为fatal以最大程度地减少写入“磁盘”。

externalModules
配置运行时将如何处理外部 npm 模块。这包括
  • 编辑器是否允许安装新的节点模块
  • 是否允许节点(例如 Function 节点)拥有自己的动态配置依赖项。

allow/denyList 选项可用于限制运行时将安装/加载的模块。它可以使用*作为匹配任何内容的通配符。

externalModules: {
   autoInstall: false,
   autoInstallRetry: 30,
   palette: {
      allowInstall: true,
      allowUpload: true,
      allowList: [],
      denyList: []
   },
   modules: {
      allowInstall: true,
      allowList: [],
      denyList: []
   }
}

编辑器配置

adminAuth
在编辑器和管理 API 中启用用户级安全性。有关更多信息,请参阅保护 Node-RED
paletteCategories
定义面板中类别的顺序。如果节点的类别不在列表中,则该类别将添加到面板的末尾。如果未设置,则使用以下默认顺序
['subflows', 'common', 'function', 'network', 'sequence', 'parser', 'storage'],

注意:在用户创建子流之前,子流类别将为空且在面板中不可见。

编辑器主题

可以使用以下设置对象更改编辑器的主题。所有部分都是可选的。

editorTheme: {
    page: {
        title: "Node-RED",
        favicon: "/absolute/path/to/theme/icon",
        css: "/absolute/path/to/custom/css/file",
        scripts: [ "/absolute/path/to/custom/script/file", "/another/script/file"]
    },
    header: {
        title: "Node-RED",
        image: "/absolute/path/to/header/image", // or null to remove image
        url: "https://nodered.com.cn" // optional url to make the header text/image a link to this url
    },
    deployButton: {
        type:"simple",
        label:"Save",
        icon: "/absolute/path/to/deploy/button/image" // or null to remove image
    },
    menu: { // Hide unwanted menu items by id. see packages/node_modules/@node-red/editor-client/src/js/red.js:loadEditor for complete list
        "menu-item-import-library": false,
        "menu-item-export-library": false,
        "menu-item-keyboard-shortcuts": false,
        "menu-item-help": {
            label: "Alternative Help Link Text",
            url: "http://example.com"
        }
    },
    tours: false, // disable the Welcome Tour for new users
    userMenu: false, // Hide the user-menu even if adminAuth is enabled
    login: {
        image: "/absolute/path/to/login/page/big/image" // a 256x256 image
    },
    logout: {
        redirect: "http://example.com"
    },
    palette: {
        editable: true, // *Deprecated* - use externalModules.palette.allowInstall instead
        catalogues: [   // Alternative palette manager catalogues
            'https://catalogue.nodered.org/catalogue.json'
        ],
        theme: [ // Override node colours - rules test against category/type by RegExp.
            { category: ".*", type: ".*", color: "#f0f" }
        ]
    },
    projects: {
        enabled: false // Enable the projects feature
    },
    theme: "", // Select a color theme for the editor. See https://github.com/node-red-contrib-themes/theme-collection for a collection of themes to choose from
    codeEditor: {
        lib: "ace", // Select the text editor component used by the editor. Defaults to "ace", but can be set to "ace" or "monaco"
        options: {
            // The following only apply if the editor is set to "monaco"
            theme: "vs", // Select a color theme for the text editor component. Must match the file name of a theme in packages/node_modules/@node-red/editor-client/src/vendor/monaco/dist/theme
        }
    },
    mermaid: {
        theme: "default" // Select a color theme for the Mermaid diagramming and charting tool. Must match the name of a theme in https://mermaid.npmjs.net.cn/config/theming.html#available-themes
    }
},

仪表板

ui
可以指定 Node-RED-Dashboard 附加节点的起始路径。这是相对于任何已定义的 **httpNodeRoot** 的

ui : { path: “mydashboard” },

节点配置

任何节点类型都可以在文件中定义自己的设置。

functionGlobalContext
Function 节点 - 附加到全局函数上下文的对象集合。例如,
functionGlobalContext: { osModule:require('os') }

可以在函数节点中访问,如下所示

var myos = global.get('osModule');
注意:在 Node-RED v0.13 之前,使用全局上下文的文档方式是将其作为 `context` 的子属性访问
context.global.foo = "bar";
 var osModule = context.global.osModule;
此方法仍然受支持,但已弃用,转而使用 `global.get`/`global.set` 函数。使用此方法存储的任何数据都不会在重新启动后持久保存,并且在侧边栏上下文查看器中不可见。
functionExternalModules
如果设置为true,则 Function 节点的“设置”选项卡将允许添加其他模块,这些模块将可供函数使用。有关更多信息,请参阅编写函数。默认值:false
functionTimeout
函数节点 - 应用于新配置的函数节点的默认超时时间(以秒为单位)。默认值:0 - 表示无超时。
debugMaxLength
调试节点 - 发送到调试侧边栏选项卡的任何消息的最大长度(以字符为单位)。默认值:1000
mqttReconnectTime
MQTT 节点 - 如果连接丢失,等待多长时间(以毫秒为单位)才尝试重新连接。默认值:5000
serialReconnectTime
串行节点 - 在尝试重新打开串行端口之前等待多长时间(以毫秒为单位)。默认值:5000
socketReconnectTime
TCP 节点 - 在尝试重新连接之前等待多长时间(以毫秒为单位)。默认值:10000
socketTimeout
TCP 节点 - 在套接字超时之前等待多长时间(以毫秒为单位)。默认值:120000