I have seen countless articles on how to use NSSM (http://nssm.cc/) to start a NodeJS process.
So, I have the following simple NodeJS file:
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end('<p>Hello World</p>');
}).listen(8000);
console.log('Server running on http://localhost:8000/');
I am using this command to install the NodeJS file as a windows service:
"C:\Program Files\SimpleNode\nssm.exe" install SimpleNode "C:\Program Files\SimpleNode\node.exe" "C:\Program Files\SimpleNode\simple.js"
The service is installed. When I start it I get an error message, the services is in the Paused state and I see the following error in Event Viewer:
GetProcessTimes() failed: The handle is invalid.
This should be pretty simple. I have tried using a domain account that has local admin rights. I have tried a couple of different port numbers. The app does work correctly when I start it from the command line.
MORE NOTES: This is running on 64-bit Windows 2008 R2 server. I have made sure I am running all 64-bit executables for both NSSM and Node. I have also tried using 32-bit executables for both.
Can anyone tell me what I am missing? Can someone else replicate this issue?
To create a service with node-windows, prepare a script like: var Service = require('node-windows'). Service; // Create a new service object var svc = new Service({ name:'Hello World', description: 'The nodejs.org example web server. ', script: 'C:\\path\\to\\helloworld.
Resolution: Create local user. Ensure local user has rights to run as a service (https://docs.microsoft.com/en-us/system-center/scsm/enable-service-log-on-sm?view=sc-sm-2019) - Local Group Policy. Have the nssm.exe ALSO accessible by the created user.
Found the issue.
The problem is that is that the path to the simple.js file has a space in it (Good Old "Program Files"). You have to escape the quotes with a backslash for NSSM to interpret it correctly. The correct installation command line is:
"C:\Program Files\SimpleNode\nssm.exe" install SimpleNode "C:\Program Files\SimpleNode\node.exe" \"C:\Program Files\SimpleNode\simple.js\"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With