gorenje / node-red-contrib-nodedev

Node-RED nodes for the development of Node-RED nodes in Node-RED
https://flowhub.org/f/b92be5062203ff69
Other
3 stars 0 forks source link
node-development node-red visual-programming

Node-RED nodes for the development of Node-RED nodes in Node-RED using Node-RED nodes.

What?

The idea behind this collection of nodes to democratise the development of Node-RED nodes. Normally the development of your own nodes will require the use of a third-party editor. Something like VSCode or Vim or Atom or Emacs. This requirement makes creating nodes that much harder. So why not create nodes for Node-RED in Node-RED? After all, if you are using Node-RED, you probably understand how to use Node-RED.

So this package tries to provide some supporting nodes for making node development in Node-RED possible and simpler. I have created a set of nodes that fulfill my needs, everything else is bound my imagination.

Imagine a continous integration server combined with an editor. This can be done because Node-RED can both editor code (using something like a function node) and also perform actions such as posting data off to servers (http request node).

What do these nodes provide?

This is all very confusing?

Of course, all this is very meta and it gets worse since these nodes are maintained by this flow. These nodes are bootstrapped in Node-RED to aid Node-RED node development within Node-RED. On the other hand, Node-RED node development is initially also confusing (requiring at least three different files). That's why the NodeFactory provides templates for various types of nodes.

This is not an inbuilt extension of Node-RED and obviously a more integrated workflow would be simpler. This is a attempt to find a better solution to Node-RED node development (not NodeJS development), one by which testing and fixing nodes becomes faster because everything is done in Node-RED.

Screencast

For a detailed explanation on how to use these nodes, check out the screencast presenting the NodeDev workflow.

Motivation

A comparison of Node-RED extensions and indirections

Link Call Subflow Link Nodes[^4] Custom Node Function node Flow Tab
Outputs [^1] =1 >=1 =1 >=1 >=1 -
Embeddable[^2] Yes Yes - Yes Yes Yes
Modifiable[^3] Yes Yes Yes - Yes Yes
Packages[^5] - - - Yes Yes -
Reusable[^6] - Yes - Yes - Yes
Button[^7] - - - Yes - -
Iconification[^8] Yes Yes Yes Yes Yes -

What this package does is make custom nodes modifiable within Node-RED.

[^1]: Number of outputs definable. Subflows can have many outputs, link-call nodes only ever have one output. Zero outputs is possible for all extensions, one is standard and more than one is difficult. [^2]: Embeddable means with the functionality can be included in a flow. Link-in/-out nodes redirect the flow of messages without those messages returning to the point where they left the original flow. [^3]: Does Node-RED provide support of modifying the extension? Node-RED does not provide any support for modifying custom nodes within Node-RED. [^4]: A combination of Link-in and Link-out nodes. [^5]: Can external NPMjs packages be included in the extension? [^6]: Is there a structured form of reusability for other flows? Subflows are structured to be reused, function nodes are not. [^7]: Can the extension be triggered with a button, i.e., as an inject node? [^8]: Can the icon be customised to make for simpler identification?

Examples

Examples are included:

Config node with sidebar

The following animation shows how the example of a config node with sidebar button works:

img

This animation shows the development and installation of a palette node:

img

Importing existing packages

Using the Package Import sidebar, it is also possible to install existing packages to find out how others have built their nodes.

The gif shows some of the features:

This animation shows those features:

img

Of course making changes to the PkgFile nodes and then reinstalling the package will reflect those changes. This makes it simple to take an existing package, make modifications to suit oneself and then push those changes upstream to the original developer(s).

Tips

How to avoid restarting Node-RED?

Normally when developing nodes for Node-RED, a restart is necessary to flush older versions of the nodes out of Node-RED. This can be avoided by renaming the package each time its installed into Node-RED. There is no need to rename nodes, just the entire once in the package.json. Something I do is use a random number as extension to the package name. The workflow then becomes:

  1. Create nodes
  2. Install nodes
  3. Using the palette manager to remove the node package
  4. Reload the browser since it too has a cache of node code
  5. Make modifications to the nodes
  6. Change the package name
  7. Reinstall the nodes
  8. Repeat from step 3

Since all this happens in the browser, there is no leaving Node-RED, making it more efficient to test and modify nodes. Renaming of packages can be done automagically as demonstrated by the flow that maintains these nodes.

Artifacts

Similar Projects

Outlook

Wherever the road shall lead, there it will go.