配置

可利用以下属性对Node-RED进行配置。

当作为一个独立程序运行时,这些属性可以从settings.js文件中获得,该文件的存放位置可能为:

  • 通过命令行参数--settings|-s设置
  • 由命令行参数--userDir|-u指定的用户目录
  • 默认用户目录: $HOME/.node-red/settings.js
  • Node-RED安装目录

Node-RED中包含一个默认的settings.js文件,当用户没有提供配置文件,就会使用这个文件。另外,它也可作为你创建自有配置文件的起点,在这里可以找到它的源码。

而当以嵌入式方式运行时,则须通过调用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
用于提供编辑器服务的端口。默认值: 1880.

仅适用于独立运行方式.

httpAdminRoot
编辑器界面的根网址。如果设置为false, 则所有管理员服务端点将被禁用,包括API端点和编辑器界面。如果想只禁用编辑器界面,请查看后面的disableEditor属性,默认值: /
httpAdminAuth
弃用: 请查看adminAuth

在编辑器界面上启用HTTP基本身份认证:

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

pass属性为实际密码的md5哈希值,以下命令可用于产生该数值:

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

仅适用于独立运行方式.

httpNodeRoot
所有提供提供HTTP服务节点的根网址。如果设置为false,则所有基于节点的HTTP服务端点被禁用。默认值: /
httpNodeAuth
启用HTTP基本身份认证,相关格式参看httpAdminAuth
httpRoot
为管理员和节点服务端口设置共同的根网址,它将覆盖由httpAdminRoothttpNodeRoot所设置的值。
https
启用https,需要指定专门的参数对象,请参看其定义.

仅适用于独立运行方式.

disableEditor
如果设为true,将会阻止运行时显示编辑器界面,但管理员应用接口将保持可用。默认值: false.
httpStatic
用于提供静态Web内容服务的本地目录,其中的内容可通过顶级网址/访问。当使用该属性时,必须同时使用httpAdminRoot属性,将编辑器界面指向/以外的其他路径。

仅适用于独立运行方式.

httpStaticAuth
对于静态内容启用HTTP基本身份认证,相关格式参看httpAdminAuth
httpNodeCors
enables cross-origin resource sharing for the nodes that provide HTTP endpoints, as defined here
httpNodeMiddleware
an HTTP middleware function that is added to all HTTP In nodes. This allows whatever custom processing, such as authentication, is needed for the nodes. The format of the middleware function is documented here.
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
currently only console logging is supported. Various levels of logging can be specified. Options are:
  • fatal - only those errors which make the application unusable should be recorded
  • error - record errors which are deemed fatal for a particular request + fatal errors
  • warn - record problems which are non fatal + errors + fatal errors
  • info - record information about the general running of the application + warn + error + fatal errors
  • debug - record information which is more verbose than info + info + warn + error + fatal errors
  • trace - record very detailed logging + debug + info + warn + error + fatal errors

The default level is info. For embedded devices with limited flash storage you may wish to set this to fatal to minimise writes to “disk”.

Editor Configuration

adminAuth
enables user-level security in the editor and admin API. See security for more information.
paletteCategories
defines the order of categories in the palette. If a node’s category is not in the list, the category will get added to the end of the palette. If not set, the following default order is used:
['subflows', 'input', 'output', 'function', 'social', 'storage', 'analysis', 'advanced'],

Note: Until the user creates a subflow the subflow category will be empty and will not be visible in the palette.

Editor Themes

The theme of the editor can be changed by using the following settings object. All parts are optional.

editorTheme: {
    page: {
        title: "Node-RED",
        favicon: "/absolute/path/to/theme/icon",
        css: "/absolute/path/to/custom/css/file"
    },
    header: {
        title: "Node-RED",
        image: "/absolute/path/to/header/image", // or null to remove image
        url: "http://nodered.org" // 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 editor/js/main.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"
        }
    },
    userMenu: false, // Hide the user-menu even if adminAuth is enabled
    login: {
        image: "/absolute/path/to/login/page/big/image" // a 256x256 image
    }
},

Dashboard

ui
The home path for the Node-RED-Dashboard add-on nodes can specified. This is relative to any already defined httpNodeRoot

ui : { path: “mydashboard” },

Node Configuration

Any node type can define its own settings to be provided in the file.

functionGlobalContext
Function Nodes - a collection of objects to attach to the global function context. For example,
functionGlobalContext: { osModule:require('os') }

can be accessed in a function node as:

var myos = global.get('osModule');
Note: Prior to Node-RED v0.13, the documented way to use global context was to access it as a sub-property of context:
context.global.foo = "bar";
 var osModule = context.global.osModule;
This method is still supported, but deprecated in favour of the global.get/global.set functions. This is in anticipation of being able to persist the context data in a future release.
debugMaxLength
Debug Nodes - the maximum length, in characters, of any message sent to the debug sidebar tab. Default: 1000
mqttReconnectTime
MQTT Nodes - if the connection is lost, how long to wait, in milliseconds, before attempting to reconnect. Default: 5000
serialReconnectTime
Serial Nodes - how long to wait, in milliseconds, before attempting to reopen a serial port. Default: 5000
socketReconnectTime
TCP Nodes - how long to wait, in milliseconds, before attempting to reconnect. Default: 10000
socketTimeout
TCP Nodes - how long to wait, in milliseconds, before timing out a socket. Default: 120000