3

How to keep a node application running in windows even when user logs off? Also how to keep running a node http-server even after user log-off?

mihai
  • 37,072
  • 9
  • 60
  • 86
Machau
  • 31
  • 1
  • 4
  • Do you mean keep the application running when the user logs out of their Windows account? – Soviut Mar 17 '17 at 09:50
  • @Soviut actually there a specific version for windows `forever-win` because the "regular one" it seems to have a bug on windows. I'll let as a comment because I didn't test...but it should work – Elmer Dantas Mar 17 '17 at 09:55
  • @Machau try installing [Forever](https://www.npmjs.com/package/forever) and or install `forever-win` (using `npm -g install forever-win`) and do then `forever start app.js` – Elmer Dantas Mar 17 '17 at 09:58
  • Souviut yes you are right . ask is to keep runnning the application when the user logs out of their Windows account. @Elmer I know about forever but its not a solution to my problem as forever will also run in user window session. We will have to again start forever once the user logs in again in Windows. Please correct me if I'm wrong – Machau Mar 17 '17 at 12:15
  • @Machau I really don't know how it will works with Windows...I think you should try. Using `Forever` in a linux server, even when I'm log out, the server still runs. So, I think that should work in the same way on Windows. – Elmer Dantas Mar 17 '17 at 13:54

2 Answers2

5

You have 2 great options. One is as mentioned in comments above Forever.

The other is PM2 which is easy to install and offers an incredible amount of options. I use this in all projects, but I cannot attest to the Windows version as I am on Linux & Ubuntu servers and work on a Mac. You can daemonize your node process, follow logs, cluster it and make sure the process reboots even with a server shutdown (it is a service).

twg
  • 1,075
  • 7
  • 11
  • Will it work with Windows as well. If yes, please let me know the specific command option for my query. If No, let me know if there is alternative to PM2 for Windows – Machau Mar 17 '17 at 12:22
  • @Machau go to the PM2 I listed above or here [PM2 @ NPM](https://www.npmjs.com/package/pm2). According to documentation it works on Windows. You can also look here: [pm2-windows-service](https://www.npmjs.com/package/pm2-windows-service) – twg Mar 17 '17 at 14:06
  • 1
    Not sure why this doesnt have more upvotes. Never heard of PM2 and I have to say it was as easy as `yarn add -D pm2` `pm2 start app.js`. Awesome. – Brandon Benefield Jun 25 '18 at 23:46
0

windows task scheduler: execute node.exe: start in project folder: and argument (app.js)