node.js http server as a Windows service

I created a simple http server in Node.js.

I wanted to make it run permanently on my Windows 2008 machine, so that, if the computer reboots, it automatically restarts.

So I made it a service with this command:

C:\Users\Administrator>sc create translate binPath= "node D:\Apps\translate\machine-learning-server\servertranslate.js" DisplayName= "Translation Server"

Then started it with:

C:\Users\Administrator>sc start translate

and got the following error message:

[SC] StartService FAILED 1053:

The service did not respond to the start or control request in a timely fashion.

The program works OK when I start it from the command line (not as a service).

What is the easiest way to have a node.js web server that restarts automatically when the computer reboots?

In the past, I've used NSSM for running Node.js applications as services on Windows. It works quite well, and can be configured to automatically restart your application in the event of a crash.

http://nssm.cc/usage

nssm install YourService "C:\Program Files\Node.js\node.exe" "C:\something\something.js"

As I recall, the Service runtime environment isn't the same as running something under the command shell. In particular, Services are required to respond to messages from the system to indicate their running status, as you've seen :-)

This must be a solved problem, though...

Sure enough: https://npmjs.org/package/windows-service

windows-service

Run Node.JS programs as native Windows Services.

npm install windows-service

At a guess, I'd say that the service doesn't know where to find the node binary. You've probably updated your profile's PATH variable. My recommendation is to ALWAYS hard code the full path in service scripts.

As mentioned in others questions about it, I'd like to share here (because it wasn't referred yet) a node.js module called WinSer that wraps NSSM and its usage is very simple, maybe it helps someone someday.

: )