[Whole Web, Node.js, PM2] Configuring PM2 for Node applications
In this lesson, you will learn how to configure node apps using pm2 and a json config file.
Let's say there are tow node apps: app1, app2.
What we want to do is create a json fie as config file for pm2.
pm2.config.json:
{ "apps": [{ "name": "App1", "script": "app1/server.js" },{ "name": "App2", "script": "app2/server.js" }] }
app1/server.js:
var http = require("http"); var server = http.createServer(function(request, response){ response.writeHead('200', {"Content-Type": "text/plain"}); response.end("Hello from app1"); }); server.listen(3000); console.log("Listen on port 3000");
app2/server.js:
var http = require("http"); var server = http.createServer(function(request, response){ response.writeHead('200', {"Content-Type": "text/plain"}); response.end("Hello from app2"); }); server.listen(3001); console.log("Listen on port 3001");
Usage:
pm2 start pm2.comfing.json