![]() ![]() $ npm i -g pm2 pm2-windows-service npm-check-updates Sadly, it did not work perfectly out of the box, so here's how we were able to get it running:įirst, you're going to need pm2, pm2-windows-service, and npm-check-updates (more on that last one in a moment). I'm happy to report that this solution is working well for us! Essentially it accomplishes the same goal: running pm2 resurrect but it also gives you that start/stop/restart control in the same interface as all the rest of your system services. It installs an actual Windows Service that will start automatically after a reboot, and which you can start/stop/restart from the Services panel. The latter, pm2-windows-service says in its readme that it was inspired by pm2-windows-startup and it takes a different approach. This doesn't seem super frail to me (certainly a step or three up from our home-rolled solution with task scheduler!) but can we do better? It installs a registry entry that runs on startup and calls wscript.exe (a system app that can run vbscript scripts) and has it run an included vbscript script that then runs the pm2 resurrect command. The former, pm2-windows-startup is much simpler in design, with fewer dependencies but it uses a more blunt approach to get the job done. I'm only linking the latter because that's the one we decided to go with. ![]() I don't know when, but at some point their official docs added some links to two community projects pm2-windows-startup and pm2-windows-service. We're using PM2 for the process management, and it has built in functionality for daemonizing and restarting your apps after a system reboot, but only for *nix systems. It's been a few years since we came up with the solution-that-shall-not-be-named, and we figured there's a decent chance that someone figured out something better since then. ![]() Recently a coworker and I went back to the drawing board on this. ![]() Trust me, the world is a better place if I don't share those detials. We actually did have a way to make it work, but it involved using the Windows Task Scheduler, and a batch file, and some tedious work any time there was a new node app to add to the mix. Gotta love em, right? But just because we have some constraints to work around doesn't necessarily mean we can't have nice things.Īs my team transitions to writing more and more of our application as node.js powered microservices, we were starting to feel the pain of not having a good solution for starting things up automatically after an OS reboot. The Digital Garden of Adam Tuttle TIL: Running Node.js Apps as a Windows ServiceĪh, legacy servers. TIL: Running Node.js Apps as a Windows Service ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
December 2022
Categories |