1

enter image description hereI have hosted my nodejs application on windows as a windows service using http://nssm.cc/ .

However, when the application crashes it does not restart automatically.

I believe windows is not notified about the crash.

Also I cannot view the logs i have written in the console of the app for debugging.

Can anyone please assist with the best way to host nodejs on windows as a service and check failure logs? Also is IISNode a better approach?

user3151766
  • 1,560
  • 1
  • 11
  • 16
  • 1
    I would try using Forever, there is a Windows fork: https://www.npmjs.com/package/forever-win – Mark B Apr 29 '16 at 13:10
  • 2
    Make use of PM2 tool. also there is pm2-windows-service module to run as service. – Hiren S. Apr 29 '16 at 13:12
  • Thanks. But what about logs? How will I get notified about errors/crash? Any idea with IIS Node? – user3151766 Apr 29 '16 at 13:17
  • Both Forever and PM2 allow you to specify logging configuration. For alerts that's a separate issue. You could use Amazon CloudWatch Logs or a third-party service like Loggly or LogEntries. – Mark B Apr 29 '16 at 13:20

1 Answers1

2

I would suggest using the PM2 module that has windows startup and service support, log and monitoring management.

Shimon Tolts
  • 1,416
  • 12
  • 14
  • i should still host node as windows service? or PM2 takes care of it? – user3151766 Apr 29 '16 at 13:28
  • PM2 runs as a service and he (re)runs your code and takes care of everytrhing – Shimon Tolts Apr 29 '16 at 13:29
  • I am getting error shown in above screenshot, can you please assist further? – user3151766 Apr 29 '16 at 13:51
  • please describe your system, OS, Node.js version, etc.. have you seen the instructions? you must have Node.js 4+ https://github.com/jon-hall/pm2-windows-service – Shimon Tolts Apr 29 '16 at 13:53
  • I am using windows 8 and node version v5.7.1. I did check the instructions. – user3151766 Apr 29 '16 at 13:58
  • i see in the error message it says "error git not found" do you have git installed? https://git-scm.com/ – Shimon Tolts Apr 29 '16 at 14:01
  • Yes, I do have git. I have noticed that the service is installed but it stops within a second after i start it. Below is error logged in event viewer - Child process [7552 - C:\Program Files\nodejs\node.exe --harmony "C:\Users\Intel_pc\AppData\Roaming\npm\node_modules\pm2-windows-service\node_modules\node-windows\lib\wrapper.js" -f "C:\Users\Intel_pc\AppData\Roaming\npm\node_modules\pm2-windows-service\src\service.js" -l "PM2" -g 0.25 -w 1 -r 3 -a n] terminated with 0 – user3151766 Apr 30 '16 at 06:14