Reputation: 888
I have developed push notification service using node js. For that I have to start the service manually each and every time.
How to start this service automatically? For example: If I logged-in, it should run automatically. thanks in advance
Upvotes: 6
Views: 8593
Reputation: 873
I use forever on linux which looks like it has a windows versions here: https://www.npmjs.com/package/forever-win
You can use this to daemonize your node apps on windows.
Upvotes: 0
Reputation: 1004
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
Upvotes: 6
Reputation: 1559
If you want to run your node application as a service, I guess that forever is the program you need to demonize your app on your computer.
I use it and it's the de-facto way in Nodejs to start a program as windows starts, without the need to open a windows session or putting anything in the startup or using the task scheduler.
Upvotes: 0
Reputation: 1274
Use Apache in Windows http://httpd.apache.org/docs/2.4/platform/windows.html. Install Apache 2 http://www.thesitewizard.com/apache/install-apache-2-windows.shtml
See this answer Apache and Node.js on the Same Server
Upvotes: 0
Reputation: 2470
There are several ways to do this,
Create a file with .cmd extension and simply add what you write on CMD Prompt to start the service as contents of this file.
node Path:\service.js 'Assumes path to node.exe is set
Right Click, and Create a shortcut of this file and drag the shortcut to the Startup folder.
Start >> All programs >> Right-click startup >> Open
Task Scheduler could also be used.
Now some NPM modules exist as well to manage node processes. Have a look at forever and PM2.
Upvotes: 0