6

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

Nisar
  • 828
  • 1
  • 10
  • 28

5 Answers5

6

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

axxis
  • 954
  • 1
  • 10
  • 18
  • I've got “the service didn't respond in a timely fashion” error, what could be wrong here? – tsds Aug 31 '20 at 13:22
0

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.

Abdullah Leghari
  • 2,332
  • 3
  • 24
  • 40
  • Thanks Abdullah, I am new to node.js. Is there any alternative to start the service instead of *.cmd. If I am move the node services to the cloud server (amazon). How to start this services? – Nisar Apr 22 '15 at 05:48
0

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

Community
  • 1
  • 1
Knase
  • 1,224
  • 14
  • 23
0

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.

formixian
  • 1,549
  • 16
  • 25
0

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.

radiofrequency
  • 873
  • 8
  • 19