How to know if PM2 runs my NodeJS app? - node.js

I've been wondering how one knows if PM2 or other similar apps run a NodeJS app? Not just knowing that the app is ran as a child process, but specifically know that PM2 is the one runs it.
I did console.dir(process), but I had yet to find anything that referred to PM2.

You should have a lot of informations in the process environnement, pm2 use it to transfer variable into application.
You can see here that the ProcessContainer (the wrapper around your application) set env var from process.env.pm2_env

Related

What is the best node process manager for Windows Server?

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?

What is process.json file in Node.js?

It seems to be basic for you to answer but still I couldn't able to find out what is process.json file in Node.js and what it does, is that any file exists in Node.js ?
I went through one of the question on stackoverflow here in which process.json file is showing when installing npm modules.
Can you please answer me about the same that will be really helpful ?
process.json is used for PM2 module of Node.js which is a General Purpose Process Manager and a Production Runtime for Node.js apps with a built-in Load Balancer.
PM2 empowers process management workflow.
Key features of PM2 are:
Simple and efficient process management (start/stop/restart/delete/show/monit)
Keep your application ALWAYS ONLINE with auto restarts and init system script generation
Clusterize Node.js Applications without code change to increase performance and reliability
Hot Reload Node.js Applications without extra configuration
Starting an application in production mode can be done using this simple command
$ pm2 start app.js
To dive into more details for process.json, you can refer this

MEAN Stack Express server going down

I am running a Node.JS + Angular JS application on a cloud server using the MEAN stack. The application is terminating every hour or sooner.
I have few thoughts and would like someone who can tell me which might a cause.
I am using SSH through root when I start the service using this command
NODE_ENV=production PORT=80 grunt serve:dist
Do I need forever to run this properly ?
Should I use a server user (similar to apache) that can run the application?
If yes how do I do this ?
We do not have a deployment engineer in our team but it is annoying to not being able to keep the app running on the server after developing the application. Please help diagnose the problem.
If you don't want to use a deployment service — MS azure, AWS, heroku, etc. (which would probably be a lot easier) — then yes, you would have to use something like forever to restart your sever every time it crashes. It's really odd that your app terminates after an hour though, it'd be helpful if you could describe why that's happening.

Is it possible to run sails.js on a node cluster?

I am currently running an express server using the node js vanilla cluster setup as demonstrated over here:
http://rowanmanning.com/posts/node-cluster-and-express/
I'd like to move the server over to sails.js and I am wondering if anyone knows how to configure sails to support the node cluster (no proxies, just simple cluster).
TX,
Sean.
First thing - if You want to use sessions, You need to use session store. Otherwise session will be not shared between instances of Your app.
Then, The easiest way is to use something like PM2, which can be found here: https://github.com/Unitech/pm2
You dont need to do changes in Your app.js files - it should be written as standard non-clustered sails app. PM2 will do the job.
Just start the app with pm2 start app.js -i x where x is number of instances or use pm2 start app.js -i max which will start instances that are equal to numbers of processors, or processor threads.
PM2 is great and very stable, it has many features to run it smoothly in producation, however it has some flaws in development. If You will ever have a problem with "port already in use" after stopping or even deleting app that was using it - You will have to use pm2 kill which will kill ALL Your apps.
Other than that - its just great - with some additional monitoring tools.
You can use PM2 Library a create different instances like cluster.
For do it you have to use app.js file, like:
pm2 start app.js
If you want to run the max number of instances availables:
pm2 start app.js -i max
check the documentation for more: https://github.com/Unitech/pm2

How to set up a node.js development environment/server (Ubuntu 11.04)

I am trying to set up a development environment for node.js. I assumed at first that it requires something similar to the traditional, "localhost" server approach. But I found myself at a loss. I managed to start a node.js hello world app from the terminal. Which doesn't looked like a big deal - having to start an app from the console isn't that hard. But, after some tweaking, I found out that the changes aren't shown in the browser immediately - you need to "node [appName here]" it again to run.
So, my question is:
Is there a software or a tutorial on how to create a more "traditional" development server on your local machine? Along with port listening setup, various configurations, root directories etc (things that are regular in stacks like XAMMP, BitNami or even the prepackaged Ubuntu LAMP). Since I'm new at node.js, I can't really be sure I'm even searching for the right things on google.
Thanks.
Take a look at :
https://github.com/remy/nodemon
it'll allow you to do - nodemon app.js
and the server will restart automatically in case of failure.
To do this I built a relatively small tool in NodeJS that allows me to start/stop/restart a NodeJS child process (which contains the actual server) and see/change configuration option and builds/versions of the application, with admin options available on a different tcp port. It also monitors said child process to automatically respawn it if there was a error (and after x failed attempts stops trying and contacts me).
While I'm prohibited from sharing source code, this requires the (built-in) child_process module, which has a spawn method that returns a child process I guess, which contains a pid (process id) which you can use with the kill method to kill said child process. Instead of killing it you could also work with SIGINT an catch it within your child application to first clean up some stuff and then exit. It's relatively easy to do.
Some nice reading material regarding this.
http://nodejs.org/docs/v0.5.5/api/child_processes.html

Resources