Windows Services with Node

1,739 views
Skip to first unread message

Eric Jacobs

unread,
Feb 14, 2012, 5:21:22 PM2/14/12
to nod...@googlegroups.com
Hello there,

I've been playing with getting a node based Windows service up and running for the last few weeks. I wrote a blog post about it here: http://www.techosaur.us/2012/setting-up-a-quick-and-easy-file-server-on-windows-with-node-js/

Now I'm trying to follow my own steps, but I'm running into problems getting the server to run as a service. I can run it manually without a problem like so:
    PS C:\users\eric\Downloads> node 'C:\Program Files (x86)\static_server\static.js' 80
    Now serving on port 80.

But when I try to run it as a service, it never comes up. From the event log, it appears to crash over and over again. The service appears to be in a state of 'paused' when i check it in services.msc. I'm thinking the issue may be with the environment. To test this, I threw these lines into the top of static.js, and tried running it as a service:

    var fs = require('fs')
      ;

    fs.writeFileSync(__dirname + '/sombrero', new Buffer('abcdefghijklmnopqrstuvwxyz'));


    PS C:\users\eric\Downloads> .\nssm.exe install bus "C:\Program Files (x86)\nodejs\node.exe" "C:\Program Files (x86)\static_server\static.js" "80" "C:\Program Files (x86)\spotterrf_node"
    Service "bus" installed successfully!
    PS C:\users\eric\Downloads> net start bus
    The bus service is starting.
    The bus service was started successfully.  

But that file never gets created, and the server never actually runs. (note, i use 'bus' as a service name when testing).

Any ideas?

--
Eric Jacobs

C. Mundi

unread,
Feb 14, 2012, 8:35:32 PM2/14/12
to nod...@googlegroups.com

1. What exactly does the Windows event log say when you drill into the details?

2. Does it still crash if you bind it to a high (unprivileged) port?

Very interested in your experience, but not sure what to think.

> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to nod...@googlegroups.com
> To unsubscribe from this group, send email to
> nodejs+un...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en

Eric Jacobs

unread,
Feb 14, 2012, 8:45:16 PM2/14/12
to nod...@googlegroups.com
On Tue, Feb 14, 2012 at 6:35 PM, C. Mundi <cmu...@gmail.com> wrote:

1. What exactly does the Windows event log say when you drill into the details?

Here is the basic run around i get from the event viewer (Event Viewer > Windows Logs > Application): 

* Started C:\Program Files (x86)\nodejs\node.exe C:\Program Files (x86)\spotterrf_node\static.js for service bus in C:\Program Files (x86)\nodejs.
* Killing process tree of process 168 for service bus with exit code 1
* Killing PID 168 in process tree of PID 168 because service bus is stopping.
* Program C:\Program Files (x86)\nodejs\node.exe for service bus exited with return code 1.
* Service bus action for exit code 1 is Restart. Attempting to restart C:\Program Files (x86)\nodejs\node.exe.
* Service bus ran for less than 1500 milliseconds. Restart will be delayed by 16000 milliseconds.

2. Does it still crash if you bind it to a high (unprivileged) port?

Yes. Port number appears to make no difference.

I'm not real sure what to think here either. I've been hammering away at this all afternoon and really have nothing to show for it. It seems like node is dying immediately after it starts, for some reason. Is anyone else on the list using windows services with node?


--
Eric Jacobs

Eric Jacobs

unread,
Feb 14, 2012, 8:54:30 PM2/14/12
to nod...@googlegroups.com
After some more testing, it appears as though the node service just doesn't work if the files are in `C:\Program Files (x86)\`. I told inno setup to throw the files into `C:\thebus\` instead, and now everything is working. Is there some sort of windows voodoo magic that you need to know before you can run services from program files? Or is program files just not the place to run services from?

--
Eric Jacobs

Angel Java Lopez

unread,
Feb 14, 2012, 8:58:24 PM2/14/12
to nod...@googlegroups.com
hmmm... spaces in folder name?

C. Mundi

unread,
Feb 14, 2012, 9:10:43 PM2/14/12
to nod...@googlegroups.com

I like inno setup, but I've never tried to use it to install an app which runs as a 32 bit service on Win x64.  (I switched to WiX a couple years ago.)

I was about to suggest replacing your test server with one which does not touch the filesysystem, but it sounds like you found the real issue. 

Please keep us posted.  With interest growing in node on Windows, your experience is relevant to a growing number of us!

C. Mundi

unread,
Feb 14, 2012, 9:15:19 PM2/14/12
to nod...@googlegroups.com

I thought the same thing but I've used innosetup with spaces (eg Program Files on x86) in the past.  But, you may be right.  Maybe it doesn't like parens... 

Simon

unread,
Feb 15, 2012, 5:43:05 PM2/15/12
to nod...@googlegroups.com
I've used Windows Service Wrapper before which uses a simple XML config file and one executable that you drop into your node app's root. It gave me no problems at all, but you have to make your node program accept a stop command (using a pid file or some other way to determine which process to kill).

Shimon Doodkin

unread,
Feb 15, 2012, 9:27:36 PM2/15/12
to nodejs
Apache's prunsrv is also good to run nodejs as service, it has 64 bit
version.

http://commons.apache.org/daemon/procrun.html

Example .bat file - https://gist.github.com/1841079


On Feb 15, 12:21 am, Eric Jacobs <e...@chomp.us> wrote:
> Hello there,
>
> I've been playing with getting a node based Windows service up and running
> for the last few weeks. I wrote a blog post about it here:http://www.techosaur.us/2012/setting-up-a-quick-and-easy-file-server-...

Stephen Vickers

unread,
Mar 23, 2013, 3:12:16 AM3/23/13
to nod...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages