9 Design: Node settings
Kazuki Nakanishi edited this page 2017-08-01 10:48:33 +09:00

The completed document of this feature is Custom node settings.


/settings API returns only the following built-in fields by default.

http://nodered.org/docs/api/admin/methods/get/settings/

A node can add their own settings to be output with the above settings API.

Adding a setting

To add a node setting, add settings object as follows.

RED.nodes.registerType("tls-config", TLSConfig, {
  credentials: {
    certdata: {type:"text"},
    keydata: {type:"text"},
    cadata: {type:"text"}
  },
  settings: {
    tlsConfigDisableLocalFiles: {
      value: false,
      exportable: true
    }
  }
});
  • setting name - This name must start with type name in a camel case. If the type name is "tls-config", setting name must start with tlsConfig (case sensitive).
  • value - The value corresponding with the object name.
  • exportable - Whether the value will be output or not.

If a node is disabled, /settings API does not show the node settings.

Output example

{
  "httpNodeRoot":"/",
  "version":"0.16.2-git",
  "nodeSettings":{
    "tlsConfigDisableLocalFiles":false
  }
}

Overwriting a node setting by settings.js

If a node setting is specified in settings.js also, a node setting specified in a node will be overwritten by the one in settings.js. To overwrite it, specify a setting with the same name. tlsConfigDisableLocalFiles:false,

The node settings in settings.js are not shown in the following cases.

  • The setting is not defined in any node.
  • A node setting sets false to exportable.
  • A node is disabled.

Use Cases

Change node color

Currently, node color is fixed in each node. Using node settings, user can change a node color as they like.

  1. Add settings object to registerType definition in nodes/core/io/21-httprequest.js as follows.
    RED.nodes.registerType("http request",HTTPRequest,{
        credentials: {
            user: {type:"text"},
            password: {type: "password"}
        },
        settings: {
            httpRequestColor: {
                value: "rgb(231, 231, 174)",
                exportable: true
            }
        }
    });
  1. Change registerType definition in nodes/core/io/21-httprequest.html as follows.
<script type="text/javascript">
    var nodeColor = RED.settings.httpRequestColor;
    RED.nodes.registerType('http request',{
        category: 'function',
        color: nodeColor,
        defaults: {
            ...
  1. Add httpRequestColor definition in settings.js
module.exports = {
    httpRequestColor: "rgb(255, 0, 0)",
    ...

You can see an http request node with red color by following the above three steps.