What is the best node process manager for Windows Server? - node.js

Our team maintains a Node-Express API in a Windows Server environment.
We've struggled to find a reliable process manager.
The Express js site lists some favored pm's, but they all seem Linux-optimized (Forever, PM2, SystemD, Strong-PM).
None of them will create a windows service to revive the process after server reboots without another module like node-windows or pm2-windows-service (based on node-windows). Node-windows works but it requires manual intervention to kill node processes when you stop the service.
Any advice out there on best process managers for maintaining a node process in Windows?
Note: I've got another question out there where I'm trying to debug our implementation of PM2: Why is PM2 not launching my Node process?

Related

How can i access nodejs terminal in production to view run time errors

I want to access node app terminal in production if there is a way, as in development we can access terminal to see activities, events and log messages, but in production(cPanel) i did not find such tool which i can use to view runtime error to solve any error in the code.
If you know any solution regard this problem, please answer me, i am looking very seriously at it.Thanks, any help will be appriciated
You're welcome 🙏🏼
Shared hosts do not have access to the terminal at all
You have to buy the virtual private server (VPS) so you can run your nodejs app and access terminal.
Use pm2 for production nodejs app.
npm i pm2 -g
PM2 is a production process manager for Node.js applications with a built-in load balancer. It allows you to keep applications alive forever, to reload them without downtime and to facilitate common system admin tasks.

Keep node in running state even after user log-off

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?
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).
windows task scheduler: execute node.exe: start in project folder: and argument (app.js)

Compute Engine and NodeJS, keep online

I have a website already developed with node.js and sails.js on "Compute Engine" but to start it, necessarily I have to write "node app.js" in the SSH console of browser. But there is a problem (since I am new to Linux and Google Cloud :)), if I want my Node app it keep online, the SSH window must be open, if I close, the Node application will terminate, like Ctrl+c. So it makes no sense to have my computer turned on, just to have the active window. So, how to keep my NodeJS app online without being in the presence of SSH console?. I know the question is illogic to some, but I would appreciate if you help me. Thanks
First of all it is not related to Compute Engine nor Node.js.
You mention that the application will terminate if you press ctrl+c and that's correct because you are running your application in the foreground instead of background. To run your application in the background you can either launch your app like this:
node app.js &
Or you can launch with node app.js and then press ctrl+z.
But just sending the application to the background wouldn't help. As soon as you disconnect from your ssh session, all programs started (background or foreground) will receive a HUP signal, in node.js you can handle that signal but the default behaviour is to close:
On non-Windows platforms, the default behaviour of SIGHUP is to terminate node
One thing that you can do to ignore the SIGHUP signal is running your app as follows:
nohup node app.js &
If you do this, your application will continue to run even when you close your ssh session. Another way to achieve this is by using the screen.
This will help you on very early stage and for development but I don't recommend using neither of these things for production. Eg: if your application crash it should be restarted. The recommended way is to use a service manager that comes with the OS: upstart, systemd, init, to name a few.
You can install forever module (https://www.npmjs.com/package/forever) to your Google compute engine using SSH window.
npm install forever -g
Then, in your node server directory, execute your server using forever.
forever start [YOUR_SERVER_FILE.js]
Now, if you close the SSH window, your node server is still on !!
Good luck!
The best solution would be using a module called forever:
https://www.npmjs.com/package/forever
You can use it this way:
forever start your_script.js

nodejs for background process, not a http server

Im new to nodejs, i am looking for a way to create a nodejs process that can run in the background. All the example I can find is to create a node http server. I don't need to listen for any web request i just need to startup a process and have it listen to a message queue.
NodeJS has enough API to be used for versatile tasks, not just HTTP Servers. You have two problems to solve:
Run Node process continuously. So, you'd need some equivalent of http.listen() so the process just don't exit. Whatever you intent to do, you'd probably need Node waiting for some external events.
Run node as a daemon or service. There are plenty of modules to help, foreman, pm2. You can make this process auto-start by using upstart on linux machines and node-window for windows.

Run at startup and monitor redis and node.js processes

I want to deploy node.js app which depends on redis. Both processes will run on the same VPS. There are plenty of examples on how to daemonize and monitor node and I've also found some uncommented configuration for redis. How do I put it together? Can I just combine these two snippets in one monitrc file?
You could use Supervisord to orchestrate the launch of Redis and your NodeJS apps (use the priority parameter to start Redis before your apps). Supervisord will automatically restart your NodeJS app if they crash.
You can then setup monit over it to be alerted when something wrong happens and to restart your NodeJS processes if they use too much memory/cpu or if they are not accessible anymore from a specific port.

Resources