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

3
  • 6
    This is not a javascript question, but rather a question of Windows' program scheduling. Commented Apr 21, 2015 at 13:15
  • 2
    Agreed. Good question, but probably belongs on a different stack exchange site, like super user. Commented Apr 21, 2015 at 13:17
  • 1
    Self-hosting apps is not very reliable. One is better off using heroku or similar. :) Commented Apr 21, 2015 at 13:18

5 Answers 5

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

Sign up to request clarification or add additional context in comments.

1 Comment

I've got “the service didn't respond in a timely fashion” error, what could be wrong here?
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.

1 Comment

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?
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

Comments

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.

Comments

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.

1 Comment

PM2 is a better alternative to Forever

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.