How to reload modified module

What is the quickest way to force Node-RED to reload a module that has been modified on disk?

Previously I have found I needed to restart Node-RED and refresh the browser, but I am wondering if there is an easier/quicker way to force the reload of a specific module.

Are there any good tutorials on developing modules? Currently using a Remote VS Code setup to edit the files on disk, but I have no idea on how to run a debugger or how best to deploy (as above). I'm OK with using Git to manage changes.

I'm not aware of a way to reload a single module - comes down to the way that node.js handles require I think.

What I do is to run my development version under PM2 with watches in place so that changed files that require a restart of node-red do so automatically.

I also develop on my main Windows PC, deploy to GitHub (publish to npmjs.org if a public release) and update other platforms from npmjs.org or GitHub as appropriate. That way, I only need to do an npm install c:\path\to\local\code, whenever I save a change, node-red simply restarts.

This also makes debugging easier if/when you need to run it. I rarely run it unless I have some really tricky problem since you have to debug the whole of Node-RED which is quite complex. I generally rely on copius console.xxx and node-red log statements. I also have a custom flow on my "live" home automation server that a custom log setting uses - via MQTT, it outputs trace-level details just for my nodes and debug level for everything else - to a web page via uibuilder.

Running Node-RED in debug mode has been covered in the forum before. When done locally, you just need to start node-red passing the --inspect flag to node.js and have a suitable breakpoint somewhere early on - I usually put it at the end of settings.js.

1 Like

Might help

But you will need to restart as nodejs offers no easy to reload modules

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.