Essentially, I regularly delete my user directory so that it may be automatically recreated upon restart of Node-RED, and I have to manually reinstall some contrib nodes that I regularly use. Which script do I need to modify in order to include these non-core nodes when the user directory is recreated?
Keep package.lock, package-lock.json and the node_modules folder. That will keep all installed nodes.
And in the userDir, run:
After recreating the userDir if you have deleted the
Thanks. To be more specific, I'm looking for something more automated like how the default user folder is created automatically on restart if it is missing, but with additional nodes. I'm trying to avoid any manual steps, but instead modifying the default script behavior, if that's possible.
For instance, delete the existing user directory, start Node-RED, new user directory is automatically created like normal BUT with additional nodes that I commonly use.
That's an interesting idea. To have perhaps a post creation script ability. An optional script that runs after the userDir is created with the default files and folders.
That would let you do things like copy additional files and folders, make changes to the package.json (which is where your installed nodes are recorded), and let you run
Sounds like that might be an interesting feature request? Unless this gets shot down straight away, you might want to change the category for this thread from general to feature requests.
I may make a separate post as a feature request, but I feel this can probably done by editing the existing scripting, but have not had enough experience diving into that to have a definitive answer.
Which existing script do you mean?
Stock .js scripts in the node-red package, like red.js. The user directory is created using local nodes when node-red is started and the user directory doesn't exist. You can already define a custom settings.js to be created in the user directory by modifying the one in node_modules\node-red, so in the stock js scripts there likely is a way to modify how the default user directory is built.
For instance, if I have a certain configuration that I always want settings.js to be in my user directory, to persist after deletion of the user directory, you can modify the one in node_modules\node-red and that will be the settings.js file used in the new user directory.
You are talking about modifying core node-red code. That works for you as a one-off but it forces you into a situation where you have to make more changes every time there is a new release of Node-RED and it forces you to distribute a custom version each time. That doesn't sound very sensible or sustainable even for just your current situation.
Then there is the possibility that this might benefit others - this is the core of open source.
Hence the reason I suggested that you should move this thread to the feature requests category so that Nick and others involved with core development will see it and be able to think about whether it is useful, whether there is an alternative and whether they would be happy with a PR.
Well an update, as this is technically feasible without modifying core code. You can modify the 'nodesDir' property of settings.js located in the core node-red directory and have your js/html files for the nodes you want to persist in the directory of that property. Any dependencies for those nodes need to exist in the core node-red node_modules directory as well.
When the user directory is created, node-red uses that settings.js file as the template for the settings.js file located in the user directory. So essentially you can have a directory containing user nodes that will persist through user directory deletes.
I'm sure this is a bastardization of the original intention of this property, but it does work, and should continue to work through node-red updates assuming that the 'nodesDir' property isn't deprecated/removed.
Have you tried installing another contrib node after the process you describe? After that do the additional modules you put in node_modules remain there?
Just tried and it seems to be working still.
Installed a new contrib package from palette manager and my my 'nodesDir' nodes are still there.
Stopped/started node-red and they're still in the palette.
Deleted the user directory and they still persist in the palette.
When adding them this way, node-red shows them under the 'node-red' package in the palette manager, and they do persist through deletion of the user directory and installation of other packages via the palette manager.
It was the additional dependencies that you said you were putting in node_modules that I was concerned about. I suspect that npm will remove them because they do not appear in package.json
But this doesn't get away from the update problem. When you install a new version of Node-RED, your amended settings.js will be overwritten and you will have to replace it.
Yes that's correct, but holds true for any modifications to settings.js i.e. credentials. Good practice i.e. taking a backup before upgrade in case issues are encountered should prevent any major problems.
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.