GithubHelp home page GithubHelp logo

hagaigold / winpm2 Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 259 KB

Node on Windows using PM2

License: MIT License

Batchfile 10.36% JavaScript 89.64%
node-windows pm2-service-windows pm2-windows pm2-windows-service windows-node pm2-windows-startup

winpm2's Introduction

Node on Windows using PM2

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.

Goals

  • 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)

What are we going to use?

  • PM2 - a production process manager for Node.js applications with a built-in load balancer.
  • WinSW - Windows Service Wrapper

Preparations

Clone or download WinPM2.
Place it in a "central" directory/location, e.g. C:\NodeApps\WinPM2, and then run:

npm install

Setup PM2

Inside the project root do the following:

  1. Open an elevated cmd terminal and run configure.bat
  2. pm2 start examples\server.js
    ** it is for testing and demo
  3. pm2 install @jessety/pm2-logrotate
  4. pm2 save
  5. pm2 kill

Note
Always use PM2 from elevated cmd terminal.

Note
Add WinPM2 directory to system paths if you wish that PM2 will be accessible from everywhere.
I believe this is not essential on a production server.

Note
the logrotate MP2 module is optional but you might like it
the command is pm2 install @jessety/pm2-logrotate NOT npm install..

 

PM2 + Task Scheduler Option

Test it

  1. cd service
  2. run pm2_task_scheduler_startup.bat
  3. open http://localhost:3000/

Go Live

  1. Set up a task scheduler with "at system startup" trigger.
  2. Reboot (& test)
  3. open http://localhost:3000/

PM2 + Windows Service

Test it

  1. cd service
  2. pm2_service_startup.bat
  3. open http://localhost:3000/

Go Live

  1. cd service
  2. open WinSW_pm2.xml and check that the settings is for your like
  3. WinSW_pm2.exe install
  4. WinSW_pm2.exe start
  5. open http://localhost:3000/
  6. Reboot (& test)

 

Notes for myself:

sc query pm2_service
sc qfailure pm2_service

Bibliography

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/

winpm2's People

Contributors

hagaigold avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.