创建新节点

扩展Node-RED的主要途径就是,向节点面板添加新的节点类型。

以下为已基本完成的章节:

计划:

  1. 代码库
  2. 自定义http端点

通则

There are some general principles to follow when creating new nodes. These reflect the approach taken by the core nodes and help provided a consistent user-experience.

Nodes should:

  • be well-defined in their purpose.

    A node that exposes every possible option of an API is potentially less useful that a group of nodes that each serve a single purpose.

  • be simple to use, regardless of the underlying functionality.

    Hide complexity and avoid the use of jargon or domain-specific knowledge.

  • be forgiving in what types of message properties it accepts.

    Message properties can be strings, numbers, booleans, Buffers, objects, arrays or nulls. A node should do The Right Thing when faced with any of these.

  • be consistent in what they send.

    Nodes should document what properties they add to messages, and they should be consistent and predictable in their behaviour.

  • sit at the beginning, middle or end of a flow - not all at once.

  • catch errors.

    If a node throws an uncaught error, Node-RED will stop the entire flow as the state of the system is no longer known.

    Wherever possible, nodes must catch errors or register error handlers for any asynchronous calls they make.