Node-Red install in windows and .node-red folder location before first running

Hello,
I have finally have node-red running on a Windows VM in Azure. Took a while but finally through PM2 I have it running as a service and not under a user. So when I log out of the RDP it stays running.

I need to make this repeatable;
The issue is that (I believe) the .node-red folder is not created until you run node-red for the first time.
Is this statement correct?

Which came first the chicken or the egg?
This is the bit I'm confused on;
In the settings.js file there is a configuration option for user dir

/** By default, all user data is stored in a directory called `.node-red` under
     * the user's home directory. To use a different location, the following
     * property can be used
     */
    //userDir: '/home/nol/.node-red/',

This would be great to hard code this, however how does node-red know where to pick up the settings file to know where this is?

I know on linux you can pass the settings location in from one of the arguments
On windows we're using PM2 to run node-red from a script

pm2 start "c:\ProgramData\nodered\node_modules\node-red\red.js" -- --savePM2 Status

Where does the script know where to too look for the settings file?
Thanks in advance
Harry

Hi, for production use, I would strongly advocate a different approach to the default install (which is designed to be easier for people with no experience).

If you have a look at my alternate node-red installer, you will see that it installs node-red locally rather than globally and pre-creates a userDir folder as a sub-folder of the node-red install folder. So you can treat both node-red and its data as a single "project" style folder structure. Great for simple backup/recovery of the whole thing.

The easiest thing to do would be to set up a UAT or pre-prod environment in this style and run Node-RED once to create all of the files and folders in the userDir. Then make a copy of the userDir for future use. Noting that some things in that folder would need to be updated on Node-RED version changes. Again, the pre-prod environment would be a suitable place to do the base updates then to apply your local settings/data over the top if required. (sorry hope that makes sense - trying to type this while on a work call :slight_smile: ). I only have a couple of environments so I do a manual compare of my settings.js file against the new node-red version and manually apply any changes to my version. Mostly, other things don't change.

Node-RED picks up the userDir from the start command. While, as you can see, there is an entry in settings.js - I'm not sure that could ever actually work! The simple start command I use is baked into the package.json as a script: node node_modules/node-red/red.js --userDir ./data. But my actual start npm script on my windows dev device is pm2 start ecosystem.config.js && pm2 logs where the PM2 config resides in the same top-level folder as node-red itself.

By the way, I wouldn't personally use a Windows server in Azure for this unless I really needed something from Windows Server. I would use a Linux (Debian) VM. Linux servers generally a lot more efficient for this kind of thing than a Windows server. Probably a fair bit cheaper to run over time.

Thank you so much, great information.
Also implemented this method as an alternative to PM2

Originally when I set up the proof of concept, I stood up an Ubuntu VM in the same resource group in Azure. My background is Unix and Linux, and this would have been my choice. However due to echo system that we have, I had to get this running under a Windows VM
Eventually we will have around 250 instances running and that number will grow. Therefore I'm working with the team to. build an installer. I know we can build images from Azure but long story short, we need this as a Windows installable.
We're getting there, this information is great thank you
Harry

1 Like