PM2 is a course of supervisor for Node.js purposes. It’s useful for working Node.js software on manufacturing atmosphere. PM2 regulate your software and restart it robotically in case of software crashes. PM2 even have an construct in load balancer for make simpler to scale purposes.
On this tutorial you’ll study to put in Angaular CLI in your Linux system. Then create a pattern Angular software. Additionally run your Angular software with PM2 on a Linux system.
To make use of this tutorial, you have to have shell to your server with sudo privileged account. Login to your server and open shell to proceed work.
Step 1 – Set up Node.js
The methods doesn’t have Node.js put in, can use under instructions to put in Node.js on their system suing NVM (Node model supervisor).
Run under command to put in NVM in your system:
curl https://uncooked.githubusercontent.com/creationix/nvm/grasp/set up.sh | bash
Then set up any Nodejs model advisable in your software. Beneath command will set up Node.js 12 in your system. You may change any model quantity as a substitute of 12.
nvm set up 12
As soon as the set up accomplished efficiently. View the put in model of Node.js and npm by working the next instructions.
Step 2 – Set up Angular CLI with PM2
Angular CLI is the command line utility to create, construct and run Angular purposes. It’s accessible as Node module to put in on any system have npm put in.
Run the under command to put in newest Angular cli software in your system:
npm set up -g @angular/cli
Additionally, set up pm2 software by working the next command:
npm set up -g pm2
At this stage your system is create to create and run angular software.
Step 3 – Create Angular Utility
Skip this step, if you have already got your Angular software. In any other case, let’s have create a pattern Angular software in your system with few easy instructions.
Create and swap to listing to maintain your Angular software.
sudo mkdir -p /var/www/apps && cd /var/www/apps
Then create a brand new software utilizing ng new command adopted by software title. Change my-angular-app with an appropriate title in your software.
ng new my-angular-app
Following onscreen instruction to allow routing and choose one of many stylesheet format. The under screenshot exhibiting that I’ve enabled the Angular routing and choose CSS for stylesheet.
Create angular software with Angular CLI
Look ahead to the set up to finish. After that this can create a listing with the identical title of your software in present listing with all recordsdata of your Angular software.
Swap to your software and begin Angular software in growth mode. By default ng serve begin software on localhost solely. I’ve used –host 0.0.0.Zero to make software accessible for distant customers.
ng serve –host 0.0.0.0
As soon as service began, Entry your software in an online browser. The default Angular pay attention on port 4200. In case another software makes use of the identical port, specify one other port utilizing –port with a port quantity.
Step 4 – Run Angular with PM2
On this step we’ll describe you to easy methods to run Angular app with pm2 command. You may set run time behaviors of pm2 by offering the inputs on command line. Right here we’re discussing with rapidly used choices with pm2. Learn one after the other and use as per your necessities.
1. This can merely begin Angular server to serve your software on 127.0.0.1 (localhost) and port 4200. After beginning service you may entry your software on from native machine solely.
pm2 begin “ng serve”
2. Right here we’re instructing ng to start out software software on all system interfaces. So any consumer can entry it from system methods. However this can nonetheless use default port 4200.
pm2 begin “ng serve –host 0.0.0.0”
3. Subsequent, you may customise your ng server command to run on particular port. For instance, under command will begin Angular software on port 8082.
pm2 begin “ng serve –host 0.0.0.0 –port 8082”
4. Change the title of your software on pm2. Use –title parameter with pm2 command adopted by your software title.
pm2 begin “ng serve –host 0.0.0.0 –port 8082” –name “My Angular App”
5. Enabling watch is one other nice function of pm2. Whereas enabling pm2 hold watch about adjustments on specified listing. It is going to additionally restart the applying after getting any adjustments in recordsdata. This reduces your ache of restarting software after making adjustments everytime.
pm2 begin “ng serve –host 0.0.0.0 –port 8082” –name “My Angular App” –watch /var/www/apps/my-angular-app
When you began your Angular software utilizing pm2. Run the next command to view the standing of your software.
Examine PM2 Standing of Angular Utility
For any points, you may run pm2 logs command adopted by the applying id exhibiting in above command. This can show software and error go browsing display screen.
pm2 logs 0
On this tutorial you might have realized to deploy Angular software utilizing pm2 on any Linux system.
run angular app in background,angular cli,deploy angular app to digitalocean,pm2 start,node run angular app,pm2 npm start,how to run angular project in ubuntu,pm2 react