How to use and PM2 run Angular Angular CLI application

Angular CLI is a command-line interface Angular framework for locally created during development, to build and run the application.

It is designed to build and test Angular project on a development server. However, if you want to permanently run in production / hold the application is active, you need to Node.js Process Manager, for example PM2.

PM2 is popular Node.js applications, advanced and feature-rich production processes management with built-in load balancer. Its feature set including application monitoring, micro efficient service management / process, restart the normal operation mode and application cluster applications and close support. In addition, it allows for easy application log management and so on.

In this article, we'll show you how to run applications that use Angular Angular CLI and PM2 Node.js Process Manager. This allows you to run continuously during application development.

Claim

You must install the following packages in order to continue on the server:

  • Node.js and NPM
  • AngularCLI
  • PM2

Note: If you have installed a Node.js and NPM on a Linux system, skip to step 2.

Step 1: Install Node.js in Linux

To install the latest version of Node.js, is first added to the system NodeSource repository, as shown, then install the package. Do not forget to be installed on the Linux distribution running the correct version of Node.js command.

$ Curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash - # 12 for Version Node.js
$ curl -sl https://deb.nodesource.com/setup_11.x | sudo - E bash - # 11 for Version Node.js
$ curl -sl https://deb.nodesource.com/setup_10.x | -E sudo bash - Version # 10 for Node.js
$ sudo APT install -y nodejs

Node.js. installed on Debian

# Curl -sL https://deb.nodesource.com/setup_12.x | bash - # 12 for Version Node.js
# curl -sl https://deb.nodesource.com/setup_11.x | bash - for Node # Version 11 .js
# curl -sl https://deb.nodesource.com/setup_10.x | bash - Version # 10 for Node.js
# APT install -y nodejs

# Curl -sL https://rpm.nodesource.com/setup_12.x | bash - # 12 for Version Node.js
# curl -sl https://rpm.nodesource.com/setup_11.x | bash - for Node # Version. 11 .js
# curl -sl https://rpm.nodesource.com/setup_10.x | the bash - Version # 10 for Node.js
# yum the install NodeJS -Y
# DNF the install NodeJS -Y [in RHEL 8 and Fedora 22 and above]

Also, development tools installed on your system to install from a native plug-in NPM and compile.

$ sudo apt install build-essential  [在 Debian/Ubuntu]
# yum install gcc-c++ make          [在 CentOS/RHEL]
# dnf install gcc-c++ make          [在 Fedora]

After installing Node.js and NPM, you can check the version using the following command.

How to use and PM2 run Angular Angular CLI application

Step 2: Angular CLI Installation and PM2

Next, a package manager npm installed Angular CLI and PM2 is, as shown in FIG. In the following commands, -g option indicates that global installation package - available to all system users.

> @angular/[email protected] postinstall /usr/local/lib/node_modules/@angular/cli
> node ./bin/postinstall/script.js

+ @angular/[email protected]
added 240 packages from 185 contributors in 25.791s

How to use and PM2 run Angular Angular CLI application

How to use and PM2 run Angular Angular CLI application

Step 3: Use the Angular CLI to create Angular project

Now enter the webroot directory server, and then created using Angular CLI, build and deliver Angular application (called sysmon-app, replace it with the name of the application).

How to use and PM2 run Angular Angular CLI application

Ng serve from the output of the command, you can see Angular application is not running in the background, you can no longer access the command prompt. Therefore, it can not execute any other commands at runtime.

Therefore, you need a process manager to manage and control the application: continuously (permanently) run it, and it is possible to automatically start at system startup, as described in the next section.

Before proceeding to the next section, press [Ctl + C] to release the command prompt to terminate the process.

Step 4: Use the Angular PM2 project run forever

To make the new application runs in the background, release the command prompt, use PM2 to provide services, as shown. PM2 can also help perform common system administration tasks, such as re-start when the fault, stop, reload the configuration without stopping and so on.

[PM2] Starting /bin/bash in fork_mode (1 instance)
[PM2] Done.
┌──────────────┬────┬──────┬────────┬────┬─────┬────────────┐
│ Name         │ id │ mode │ status │ ↺  │ cpu │ memory     │
├──────────────┼────┼──────┼────────┼────┼─────┼────────────┤
│ linuxidc-app │ 1  │ fork │ online │ 32 │ 0%  │ 497.0 MB   │
│ linuxidc-app │ 2  │ fork │ online │ 0  │ 0%  │ 6.5 MB     │
└──────────────┴────┴──────┴────────┴────┴─────┴────────────┘
 Use `pm2 show <id|name>` to get more details about an app

How to use and PM2 run Angular Angular CLI application

Then, to access the Web interface of the application, open a browser and using the address http: // localhost: 4200 navigate, as shown in the following screenshot.

How to use and PM2 run Angular Angular CLI application

Angular CLI Home: HTTPS: //angular.io/cli
PM2 home page: http: //pm2.keymetrics.io/

In this guide, we show how to use Angular CLI and run Angular PM2 Process Manager application. If you have any other ideas to share or ask questions, please contact us comments box below.

Guess you like

Origin www.linuxidc.com/Linux/2019-08/159862.htm