- PM2 is a Process Manager for NodeJS and IOJS application in production environment.
- PM2 supports Express,Hapi,Geddy and Sail etc framework for NodeJS based web application.
- PM2 helps the application to run forever,reload application without downtime and common admin tasks
- In this Demo, “We will learn to install,configure the PM2 in Window”.
- PM2 module can be installed using npm install pm2 –save-dev command.The following screenshot shows the terminal with PM2 installation.
- We can also install the PM2 module globally using npm install pm2 –g command.The following screenshot shows the terminal with PM2 global installation.
- To demonstrate PM2 we have created a project named PM2Demo application.The structure of PM2Demo is as follows:-
- The server.js file contains code for dummy application.The code content of server.js are as follows:-
var http = require('http'), server = http.createServer(function(request,response){ response.end("Response From Node Server"); }); server.listen(3000, function(){ console.log("Server started at port: 3000"); });
- The server.js file can be run using node server.js command .The following screenshot shows the terminal with server.js in execution.
- The output of this demo will look like following screenshot:-
- Now we can configure PM2 in Windows using some DOS command. The following screenshot shows NodeJS command prompt CLI opened in Administrative mode with DOS command executed:-
- We can start the server.js file using pm2 start server.js command.The following screenshot shows the pm2 command in execution.
- In upcoming posts we will learn more about PM2.Till then stay tuned.
- The demo code can be downloaded from the following URL:-
https://github.com/saan1984/PM2Demo