- What is PM2?
- Why We Use PM2?
- How to Setup PM2 in the NodeJs Application (https://egghead.io/lessons/node-js-configuring-pm2-for-node-applications)
- UseCase Of PM2
- PM2 Commands
- PM2 Code Sample
- PM2 List
- How to Pass the Environment Variable using PM2? (https://egghead.io/lessons/node-js-passing-environment-variables-to-node-js-using-pm2)
PM2 Official website: PM2
Installing PM2:-
By using this command we can install the pm2 globally in our system
- npm install pm2 -g
- pm2 init simple
File /Users/admin1/Desktop/sampleapp/ecosystem.config.js generated
ecosystem.config.js
PM2 Useful Commands
- pm2 start ecosystem.config.js
- pm2 stop ecosystem.config.js
- pm2 restart ecosystem.config.js
- pm2 reload ecosystem.config.js
- pm2 delete ecosystem.config.js
How to Pass the Environment Variable using PM2?
module.exports = {
apps : [{
name : "application1",
script : "./index.js",
env_production: {
NODE_ENV: "PROD"
},
env_development: {
NODE_ENV: "DEV"
}
}]
}
For Reference Here I have mentioned the proper video explanation for How To Pass the Environment Variable using PM2
What is PM2?
PM2 is nothing but a Production Process Manager for the Node JS applications. By Using PM2 We can monitor
the Error logs, System logs,
and memory size, Process ID (Pid),
CPU (Central processing unit)
Mem (Node Memory).
PM2 Has a Build In load balancer for Node Js Production Application. It Allows Us to keep the Node Js Application Process alive Forever.
Main Use Case of the PM2 Setup, We can reload the node server without downtime so it will not affect the user in the production server
3. How to Setup PM2 in the NodeJs Server?
4.UseCase Of PM2
5.PM2 Commands
6. PM2 Code Sample