How to start the node service automatically?

I developed a push notification service using node js. To do this, I have to start the service manually every time.

enter image description here

How to start this service automatically? For example: if I logged in, it should start automatically. thank you in advance

+6
source share
5 answers

If you need a Windows service that starts when Windows starts, you can use the sc create command to create the service.

eg.

sc create MyServiceName binpath= "C:\Program Files\nodejs\node.exe C:\somefolder\service.js" start= auto depend= "Tcpip/Afd" DisplayName= "A friendly name for my service" 

Remember the spaces after the = signs.

You can find more information here: https://technet.microsoft.com/en-us/library/cc990289.aspx

If you want the application to start when you log in, you can use regedit.exe to create the REG_SZ entry containing your command in the following registry path:

HKEY_CURRENT_USER \ Software \ Microsoft \ Windows \ CurrentVersion \ Run

+4
source

There are several ways to do this,

Create a file with the extension .cmd and just add what you write to CMD Prompt to start the service as the contents of this file.

 node Path:\service.js 'Assumes path to node.exe is set 

Right-click and create a shortcut for this file and drag the shortcut to the Launch folder.

Start โ†’ All programs โ†’ Start with the right mouse button โ†’ Open

Task Scheduler can also be used.

Now there are some NPM modules for managing node processes. See forever and PM2 .

0
source

If you want to run the node application as a service, I suggest that forever is the program that you need to demonize the application on your computer.

I use it, and this is the de facto way in Nodejs to run the program as the windows start up, without having to open a Windows session or put something in autorun or using the task scheduler.

0
source

I use forever on linux, which looks like this: there are Windows versions here: https://www.npmjs.com/package/forever-win

You can use this to unmount your node applications on windows.

0
source

Source: https://habr.com/ru/post/985599/


All Articles