learn how to pass environment variables to your node.js app using the pm2 config file. This is useful for setting options inside your app such as production or development.
pm2.config.json:
{ "apps": [{ "name": "App1", "script": "app1/server.js", "log_file": "log/app1.log", "error_file": "log/app1-err.log", "watch": true, "ignore_watch": ["file"], "env": { "STATUS": "GOOD" } },{ "name": "App2", "script": "app2/server.js", "log_file": "log/app2.log", "error_file": "log/app2-err.log" }] }
app1/server.js:
Use process.env.STATUS to get the value:
var http = require("http"); var server = http.createServer(function(request, response){ response.writeHead('200', {"Content-Type": "text/plain"}); response.end("Hello from app, is this reload? " + process.env.STATUS); }); server.listen(3002); console.log("Listen on port 3002");