Create a node without restart node-red

#1

when I created a node and put it input "/nodes",I must restart node-red to load it. so,Can we have any method to load a node without restart node-red?

0 Likes

#2

Hello,
I'll take the problem the other way around: why wouldn't you want to restart node-red ?

0 Likes

#3

I think if it is possible to enable/reload a node module, why not

I'm used to the notion if I npm install that a restart is necessary. This sometimes stops me doing things till a convenient time (and sometimes that's good) but there have been occasions where I'd wished for this feature to get me out of a hole. E.g. to add some functionality without my flow restarting.

0 Likes

#4

You could just restart Node-Red but that would mean losing Node states !
We could hope for a stageful restart but that leads to a whole bunch of things to be implemented...(https://github.com/node-red/node-red/issues/698#issuecomment-231039213)

Adding functionality on runtime is tricky, not sure of how that could be done generically in Node-red.
(not answering but trying to push discussion forward...)

0 Likes

#5

If you load nodes via the editor (mange palette option) - then they automatically get added to the menu and can be used right away. If you add them manually then the runtime doesn't know about it until you restart and it rescans the directories.

0 Likes

#6

Just some brainfarts;

node-red-start -dev 'node-contrib-...'
And then whenever you deploy, it scans the directory of the node(s) in the -dev flag ?

I obviously don't know what this would entail.

0 Likes

#7

Because I don't want to restart the processes that are running, for example, the real-time statistics process.

0 Likes

#8

Node-RED does provide an API that lets to be installed without restarting the process; this is what the palette manager uses in the editor - https://nodered.org/docs/api/admin/methods/post/nodes/

Your node will need to be packaged properly as a module, with a package.json file etc.

It can only be used to install a module - it cannot be used to reload a module already loaded. If you want Node-RED to reload your node because you've changed something, then you must restart node-red. There is no avoiding that.

0 Likes

#9

this API is used to install module by npm,but when I create a new node and put it into /nodes,can I have any function to load it without restart node-red?

0 Likes

#10

How does the palette manager do a node upgrade then?

0 Likes

#11

It runs the npm install of the new version and then tells you to restart in order to complete the upgrade.

0 Likes

#12

Oh yes, so it does. Sorry for the noise.

0 Likes

#13

have same problems.

0 Likes

#14

Hi - see Nick's first answer above - Create a node without restart node-red

0 Likes

#15

Node-RED uses Node.JS and npm - so it is constrained by how those work. As others have mentioned, it isn't easy to hot-reload a module since that isn't directly supported by Node.js.

What you can do is to use something like PM2 or Nodemon to monitor the source folder of your node and make Node-RED automatically restart on change.

To get round (partially) the loss of global/flow variables on restart, redefine your default variable store as filesystem instead of memory on your development environment.

0 Likes