You can run your multiple nodejs applications many ways like using nginx server, pm2 module, forever modules, etc.
Here, we will discuss on pm2 module, forever module and by using the command prompt(node).
=>Using pm2 module
PM2 is a most familiar and General Purpose Process Manager and a Production Runtime for Node.js apps with a built-in Load Balancer.
By using pm2 module we use built-in admin lever features to manage CPU and load balancer.
you can install pm2 module globally like as bellow.
we can start multiple nodejs application like as bellow.
go to your main project directory and then run following command.
By using above command your all applications like server, app, demon will run simultaneously.
pm2 list will display all started applications. You can also stop, restart and manage all applications.
=>Using Forever module
Forever is also most familiar and a simple command line module for run Node.js application continuously. if your app encounters an error and crashes, forever will take care of this issue and restart it automatically.
you can install forever module globally like as bellow.
go to your main project directory and then run following command.
By using above command your all applications like server, app, demon will run simultaneously.
forever list will display all started applications. You can also stop, restart and manage all applications.
=>Using command prompt (node)
if you want your application using node without any external third-party module. you can start this all nodejs applications by using node or nodejs.
for start, multiple applications go to your main project directory and then run following command.
By using this method on close running application only last running application will stop and rest are continue in the background.
To stop this, check stop running nodejs application link.
in your local pc you can use this feature but in the live server, you must have to use any third party module or nginx server or any other server. because on close cmd nodejs application will stop.
now use this to run multiple nodejs applications simultaneous.
Here, we will discuss on pm2 module, forever module and by using the command prompt(node).
=>Using pm2 module
PM2 is a most familiar and General Purpose Process Manager and a Production Runtime for Node.js apps with a built-in Load Balancer.
By using pm2 module we use built-in admin lever features to manage CPU and load balancer.
you can install pm2 module globally like as bellow.
npm install pm2 -g
we can start multiple nodejs application like as bellow.
go to your main project directory and then run following command.
pm2 start server.js && pm2 start app.js && pm2 start demon.js && pm2 list
By using above command your all applications like server, app, demon will run simultaneously.
pm2 list will display all started applications. You can also stop, restart and manage all applications.
=>Using Forever module
Forever is also most familiar and a simple command line module for run Node.js application continuously. if your app encounters an error and crashes, forever will take care of this issue and restart it automatically.
you can install forever module globally like as bellow.
npm install forever -g
go to your main project directory and then run following command.
forever start server.js && forever start app.js && forever start demon.js && forever list
By using above command your all applications like server, app, demon will run simultaneously.
forever list will display all started applications. You can also stop, restart and manage all applications.
=>Using command prompt (node)
if you want your application using node without any external third-party module. you can start this all nodejs applications by using node or nodejs.
for start, multiple applications go to your main project directory and then run following command.
node server.js & node app.js & node demon.js
By using this method on close running application only last running application will stop and rest are continue in the background.
To stop this, check stop running nodejs application link.
in your local pc you can use this feature but in the live server, you must have to use any third party module or nginx server or any other server. because on close cmd nodejs application will stop.
now use this to run multiple nodejs applications simultaneous.
No comments:
Post a Comment