Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start node service automatically?

Tags:

node.js

I have developed push notification service using node js. For that I have to start the service manually each and every time.

enter image description here

How to start this service automatically? For example: If I logged-in, it should run automatically. thanks in advance

like image 786
Nisar Avatar asked Apr 21 '15 13:04

Nisar


People also ask

How do I restart node server automatically?

Nodemon is a package for handling this restart process automatically when changes occur in the project file. It will show the version of nodemon as shown in the below screenshot. Now, when we make changes to our nodejs application, the server automatically restarts by nodemon as shown in the below screenshot.

How do I run a nodeJS program automatically?

To restart the application automatically, use the nodemon module. This local installation of nodemon can be run by calling it from within npm script such as npm start or using npx nodemon.

How do I start a nodeJS service?

Node.js files must be initiated in the "Command Line Interface" program of your computer. How to open the command line interface on your computer depends on the operating system. For Windows users, press the start button and look for "Command Prompt", or simply write "cmd" in the search field.


1 Answers

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

e.g.

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"

Mind the spaces after the = signs.

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

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

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run

like image 167
axxis Avatar answered Oct 10 '22 08:10

axxis