Node.js Application as a Windows Service (With registry fix)
In my case, command nssm install MyWebService… was unsuccessful, the problem was that app.js can’t find config.json file.
First you will need:
- Node.js application (project) which you want to run as a Windows Service
1 step: Set your Node.js application as Windows Service
Download nssm.exe and put file into you node.js project folder
Run Windows Command Processor (cmd.exe) as administrator and go to your node.js project folder
Run command npm install
Run command node src\app.js and allow access through Windows firewall
Run these two commands
nssm.exe install MyWebService "C:\Program Files\nodejs\node.exe" "C:\Service\src\app.js"
net start MyWebService
Now we need to fix this error.
2 step: Edit registry
Open registry editor (regedit.exe) and go to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\MyWebService\Parameters
Now we need to change AppDirectory from C:\Program Files\nodejs to C:\Service
Restart computer and don’t forget to run Apache, MySQL or any other necessary servers for your project after restart.