For a reason beyond nature you need to run node server/app on window.
Here is some of the options that I found useful:
- Use docker
- PM2 + Windows Task Scheduler
- PM2 + Windows Service
Note
You probably can use the below methods with other P(rocess) M(anager)s, use your own wrapper or run node directly.
- Simple
- Install PM2 in the local node_modules folder
On windows,NPM install -g
is not always what you think it is :) - Don't mess up with system paths (there is one exception that I will mention below)
- PM2 - a production process manager for Node.js applications with a built-in load balancer.
- WinSW - Windows Service Wrapper
Clone or download WinPM2
.
Place it in a "central" directory/location, e.g. C:\NodeApps\WinPM2
, and then run:
npm install
Inside the project root do the following:
- Open an elevated cmd terminal and run
configure.bat
pm2 start examples\server.js
** it is for testing and demopm2 install @jessety/pm2-logrotate
pm2 save
pm2 kill
Note
Always usePM2
from elevated cmd terminal.
Note
AddWinPM2
directory to system paths if you wish thatPM2
will be accessible from everywhere.
I believe this is not essential on a production server.
Note
thelogrotate
MP2 module is optional but you might like it
the command ispm2 install @jessety/pm2-logrotate
NOTnpm install..
cd service
- run
pm2_task_scheduler_startup.bat
- open http://localhost:3000/
- Set up a task scheduler with "at system startup" trigger.
- Reboot (& test)
- open http://localhost:3000/
cd service
pm2_service_startup.bat
- open http://localhost:3000/
cd service
- open
WinSW_pm2.xml
and check that the settings is for your like WinSW_pm2.exe install
WinSW_pm2.exe start
- open http://localhost:3000/
- Reboot (& test)
sc query pm2_service
sc qfailure pm2_service
I read it so you don't have to, but at the end, it is up to you.
https://github.com/jessety/pm2-installer
https://github.com/coreybutler/node-windows
https://gist.github.com/zubair1024/8f6126db7ffbafd706f0e328ef8d4662
more at https://stackoverflow.com/