Starting Node-red from Task Manager vs. command line... not the same node-red?

I am using Windows 11 and installed NSSM to open Node-RED directly from the task manager as a service..

^^ this works cool.... I am just learning about it, come next day, and still have the same Node-RED.

But!!!! If I run node-red from the command line, it seems to open a completely different Node-RED ??

How can tap into the same Node-RED from the command line as the one I am using in task manager???

It seems like the command line gets to the settings.js file, but that is it... it doesn't keep my nodes, flows, background, etc...

The NSSM for task manager is configured like this:

Path: C:\Users\EdgarLindo\AppData\Roaming\npm\node-red.cmd
Startup directory: C:\Users\EdgarLindo.node-red
Argument: --settings "C:\Users\EdgarLindo.node-red\settings.js"
Service Name: node-red

And the command line looks more like this:

C:\Users\EdgarLindo>node-red --userDir

27 Jan 12:36:48 - [info]

Welcome to Node-RED

===================

27 Jan 12:36:48 - [info] Node-RED version: v4.1.3

27 Jan 12:36:48 - [info] Node.js version: v24.4.0

27 Jan 12:36:48 - [info] Windows_NT 10.0.26200 x64 LE

27 Jan 12:36:49 - [info] Loading palette nodes

27 Jan 12:36:49 - [info] Settings file : C:\Users\EdgarLindo.node-red\settings.js

27 Jan 12:36:49 - [info] Context store : 'memoryOnly' [module=memory]

27 Jan 12:36:49 - [info] Context store : 'file' [module=localfilesystem]

27 Jan 12:36:49 - [info] User directory : \Users\EdgarLindo.node-red

27 Jan 12:36:49 - [warn] Projects disabled : editorTheme.projects.enabled=false

27 Jan 12:36:49 - [info] Flows file : \Users\EdgarLindo.node-red\flows.json

27 Jan 12:36:49 - [info] Creating new flow file

27 Jan 12:36:49 - [warn]


Your flow credentials file is encrypted using a system-generated key.

If the system-generated key is lost for any reason, your credentials

file will not be recoverable, you will have to delete it and re-enter

your credentials.

You should set your own key using the 'credentialSecret' option in

your settings file. Node-RED will then re-encrypt your credentials

file using your chosen key the next time you deploy a change.


27 Jan 12:36:49 - [warn] Encrypted credentials not found

27 Jan 12:36:49 - [info] Server now running at http://127.0.0.1:1880/

27 Jan 12:36:49 - [info] Starting flows

27 Jan 12:36:49 - [info] Started flows

Do I have to run the command line from any specific folder????

No. The usual issue is not understanding what user the system is using - Node-RED in its default installation (installed globally), it expects the userDir to be in the home folder of the account that runs node-red.

When you run as a service, what is Windows choosing as the "user" account? Might not be quite what you expect. Obviously, when you run it manually, the account you are signed in with will be used. Check the folders under C:\Users to see if any of them have unexpected .node-red sub-folders.

Personally, I recommend NOT using the default installation but instead creating a specific folder, install node-red to that and create a sub-folder called data and use that as the userDir. settings.js will, of course, be in that folder automatically. Now you always know where everything is and you don't have to keep hunting it down.

2 Likes

I also tried to use this command below in the command line, but gave the a new Node-RED and not the one I am using in Task Manager... its seems that the command line catches the settings.js file, but nothing esle...

node-red --userDir "C:\Users\EdgarLindo.node-red" --settings "C:\Users\EdgarLindo.node-red\settings.js"

I fully agree with Julian. You see "different" node-reds since they run (without you knowing) from different folders. I always specify the userDir explicitly.
For example - here is the type of batch file I use to invoke Node-red as a Windows service with NSSM:

@echo off
echo Installing service for Node-red environment no. 7...
nssm install Node-Red-7 "C:\ProgramData\npm\node-red.cmd"
nssm set     Node-Red-7 AppDirectory "C:\ProgramData\node-red"
nssm set     Node-Red-7 AppParameters "-u C:\ProgramData\node-red -p 1881 > C:\ProgramData\node-red\node-red-7.log"
nssm set     Node-Red-7 Description "Node-red env 7 (1881)"
nssm start   Node-Red-7

Note, that I typically run node-red as a service only for production environments. During development, I prefer to run it from cmd-line, where I can visually see exceptions & crashes as soon as they happen, without having to search logs. Moreover, since the service restarts itself after a crash, the server proc can be crashing/restarting behind the scenes without you knowing (and with no indication in the log which is being re-initialized too).

I got it..

Apparently i have to run command line as administrator... then i have to nssm start node-red and it works

Running Node-RED as admin is not a good idea at all. It gives massive access to your system and could destroy it quite easily.

I only run dev on Windows, live is always on Linux. But my dev system(s) run under PM2 which gives auto-restart including after key file changes and gives easier access to logs. No need to mess with services for a dev system.

If you do want to run as a service, create some limited accounts to run it under. Running under admin will catch you out one way or another at some point.

I was looking for a way to run the very same Node-RED I use from Task Manager as a service, and tap it from command line... but I can't get the same one, as command line seems to open a new instant...

The only way to find it was to run it as administrator.

Either way... since I can't find from the command line, then I will only run it either from the command line, or only from the task manager..

Since I am just learning about Node-RED this isn't a big deal for now, but later on I will need to know how to work from an specific Node-RED, properly save the work, and later be able to transfer it to another computer..

Ahem

Now you start to see the reason for that advice.

:mx_claus:

Running stuff under Windows is rather more complex than doing so under Linux. However, the same principals apply. As already stated, you should take control of things yourself. Install node-red "locally" and create a data sub-folder to use as the userDir. Then you have full control and an easy way to back up.

The easiest way to then run from either the command line or as a service is to use PM2. This does add some overheads but takes care of all the heavy lifting for you. If you only run node-red automatically AFTER you log in (which obviously means that it won't be running if you have rebooted and not logged in), that is the easiest to work with and you can simply tell task manager to start the PM2 task shortly after login. This is what I do, it starts a terminal session so you can see the log. You can ctrl-c the terminal session and then there are easy commands to either restart node-red or terminate pm2 completely. I use some npm scripts defined in the package.json for my node-red folder:

  "scripts": {
    "start": "pm2 start ecosystem.config.js && pm2 logs",
    "restart": "pm2 restart Node-RED --update-env && pm2 logs",
    "log": "pm2 logs",
    "update": "npm install --unsafe-perm --production node-red",
    "debug": "node --inspect node_modules/node-red/red.js --userDir ./data",
  },

NB: The above assumes you are using PowerShell, cmd prompt is slightly different.