Running as a service on a windows OS

Hi TotallyInformation, I know this is kinda old topic, but I appreciate if you can reply.
I used your alternate-node-red-installer and it works really fine.

But I don't know how am I going to create an automatic start of my node-red. What I want is, if every time I logged on to my PC, I don't need to type the "npm start" to the master folder anymore, but instead it will automatically run it in the background (no windows command pop out, pretty similar on running an application as a service on a windows OS).

Hoping for your suggestions.

With kind regards,
Henjoe

Search this forum for nssm. It will permit you to run node-red as a service in Windows (so you don't even need to log in). Just be sure to use the same account for nssm as you do now (u unless you have setup nodejs for paths to be truly global)

As Steve says, there is a tool that lets you create a Windows service definition from an executable and that can certainly be used and is probably the best way over all.

Alternatively, you can use the Windows Task Manager to start applications in different ways and at different times. If you do things this way, you will need to think about whether you want to run Node-RED all of the time - e.g. even if you are not logged in - or just when you are logged in.

You will also want to familiarise yourself as to where Node-RED log output goes which also depends on how you start it.

One thing that some people do in order to make the logs more accessible and familiar (if you are used to Linux logs) is to use PM2 to actually run Node-RED since that has its own log handler. You can also set that up to run as a service or from Task Manager. I use PM2 when running Node-RED on my PC as that is my development environment so I don't have it running all the time. I have a shortcut set up and available on my Start Menu that starts Node-RED via PM2 and immediately streams the log, this is a cmd shortcut so it leaves the log streaming in a window.

Just for completeness, NSSM can also direct stdout/stderr etc to a logfile (and do rotation)

image
image

NOTE: I split this thread from an old (unrelated thread Copy Node-red Install on Windows server offline)

2 Likes

Hi steve!

Thanks for this! I actually done this before using the nssm, however my nodered that time was installed globally.
I just need to run the built-in "node-red.cmd" under "C:\Users\AppData\Roaming\npm" folder.

I know how nssm works, but however I don't know what file do I need to run when using the alternate-node-red-installer.

Again, higjly appreciated your replies.

With kind regards,
Henjoe

the same command you run now!

image

or

image

Did you try?

OMG!
I don't know why I never knew this haha.

Let me try this when I get back to my computer.

Thanks with regards,
Henjoe

otherwise you can try this:

User has to be logged on for that method though & he'll get no log file unless he pipes it & even then, no log file rotation etc..

1 Like

If you want to run the locally installed version of Node-RED as per my alternate installer, the command you need to put into nssm is the one listed in the package.json file under scripts:

"start": "node ./node_modules/node-red/red.js --userDir ./data",

Though you need to change the relative paths to absolute ones.

Hi Steve so this is my master directory,

On the side of nssm, under Application and Path, what should I select in here?
I tried to select the package.json with the following parameters:

image

But there we'ere errors and I cannot start my node-red.
Is there any invalid configuration I did?

Thank you!

Regards,
Henjoe

Hi Totally Information,

I believed you are the who created the alternate-node-red-installer,
How do you do the automatic run of the node-red?
Just like what Steve says, using the nssm, I just don't what parameters need to fill out.

I highly appreciated if you can send a sample of configuration.

Thank you.

With kind regards,
Henjoe

Did you set the login on nssm? By default it will run as service which is a different account to how you currently run node-red. You would be MUCH better off moving that folder out of desktop to somewhere the system or network service account can access.

Hi Steve, the folder is currently in Dekstop at 40800736 user,

I also used this user to run the service created by nssm.
Does it sounds wroing? Do I need to restart my computer for this?

I am actually get confused on this parameter of nssm:
image

When node-red installed globally, I used this built-in "node-red.cmd" which can be found here:

I am really confused what will be the replacement of this application when using the "alternate-node-red-installer"

Thank you.

With kind regards,
Henjoe

Show me the "log on" tab

image

Hi Steve fyr.

Thanks with kind regards,
Henjoe

As i said before...

Sorry Steve,

I get confused in here.
Do you mean I'll put my folder into C:\MyFolder ?

Thanks with kind regards,
Henjoe

TBH, the way windows sets up nodejs is rubbish.

It pusts "global" install stuff in "users" folders etc.

Now, I dont know the anatomy of Julians "Alternative installer" but I had rather hoped it installed in a
completely independent folder. Looking at your screen shot - i see its located in user\appdata\roaming\npm - that is unexpected.

so either you placed it there or you are using a mix of normal node-red install & julians installer - something doesnt look right.

Hang with me - I'll get to a resolution for you - lets get this to a sane condition.

  1. show me the content of the "node-red.cmd" that you circled.
  2. show me the shortcut you normally launch node-red with (i need to see the path of the shortcut and the content of that shortcut

Hi Steve,

This is the code under the "node-red.cmd".
image
Just for the information,
I have 2 instance of nodered, first is the node-red which is installed globally,
and the other is the "alternate-node-red-installer". I can run the node-red instance automatically (the one who is installed globally).

Do I need to edit the code for this "node-red.cmd"?

Thanks.

WIth kind regards,
Henjoe