How Can I run PM2 with Angular-Cli? - Angular2

run angular app in background
how to run ng serve in background
pm2 serve
node run angular app
command for run angular project
how to start angular app in background in ubuntu
how to run angular project on ubuntu
angular universal deploy nginx

How can I run: ng serve --prod with pm2?

ng serve from angular-cli, Angular2. I'm running on DigitalOcean.

I have tried to test with http-server -p 4200 -d false in the dist/ folder after ng build --prod

When I request from the domain, i got 404 error: (I've already setup nginx to listen to port 4200.

I test with http-server because I think I maybe can run pm2 through this command pm2 start my_app_process.json where


    "apps": [
            "name": "angular",
            "cwd": "~/angular2",
            "args": "-p 4200 -d false",
            "script": "/usr/bin/http-server"

Any better ideas of how to get it working with PM2?

This command would work as expected:

after I run

ng build --prod

then run the following command in the dist/ folder

pm2 start /usr/bin/http-server -- -p 8080 -d false


I have found a better solution: which ng then it will print /usr/bin/ng then type this

pm2 start /usr/bin/ng -- serve --prod

js and NPM installed on your Linux system, jump to Step 2. Step 1: Installing Node. js in Linux. Step 2: Installing Angular CLI and PM2. Next, install Angular CLI and PM2 using the npm package manager as shown. Step 3: Creating an Angular Project Using Angular CLI. Step 4: Running Angular Project Forever Using PM2. Step 4: Running Angular Project Forever Using PM2. To make your new application run in the background, freeing up the command prompt, use PM2 to serve it, as shown. PM2 also aids common system administration tasks such as restarting on failure, stopping, reloading configurations without downtime, and much more.

But, if you need ng serve for dev in preprod env, you can create a at root of your project

ng serve --host --port xxxx

And use pm2 like that :

pm2 start --name my-pretty-dev-app-run-on-preprod


How can I run: ng serve --prod with pm2? ng serve from angular-cli, Angular2. I'm running on DigitalOcean. I have tried to test with http-server -p 4200 -d false in  Pro Tip two commands to remember when messing with nginx: sudo nginx -t will test your configuration and run sudo service nginx restart after saving changes. {: .notice–info} PM2. Finally, I wanted to use pm2 to keep the new Angular site up and running. Over time I have created a collection of apps.

With PM2 recent version

pm2 ecosystem

than update

ecosystem.config.js as follows

module.exports = {
  apps : [{
    name: 'demoapp',
    script: 'node_modules/@angular/cli/bin/ng',
    args: 'serve --host [yourip] --disable-host-check',
    instances: 1,
    autorestart: true,
    watch: false,
    max_memory_restart: '1G',
    env: {
      NODE_ENV: 'development'
    env_production: {
      NODE_ENV: 'production'

  deploy : {


pm2 start & pm2 save

Angular. I used the angular-cli to create an app. When the app was Finally, I wanted to use pm2 to keep the new Angular site up and running. Setting up Angular 2 in your application is quite time-consuming compare to AngularJS 1. For setting up Angular 1.x, all you need to do is to just add the reference of library but with Angular 2, it requires some more work due to dependency on Grunt or Gulp for build process, TypeScript and it’s compiler.

ng is a node module after all.

- name: ngserve
  script: 'node_modules/@angular/cli/bin/ng'
  args: 'serve --progress=false --live-reload=false --disable-host-check=true'
  watch: false
  log_date_format: YYYY-MM-DD HH:mm
  merge_logs: true
  out_file: "/dev/null"
  error_file: "/dev/null"

Let's start by installing PM2 through npm on our local machine first. (You can use I'll run through creating and serving Angular, React and Gatsby applications. To install these npm install -g @angular/cli. If all goes well,  This is the Folder structure i have made for a project made in angular 2. I have deleted the Node-Module folder and other folder in order to fit it here. For styling i have only used Bootstrap. I have not used Angular-CLI. Can anyone guide me how should i deploy it ? Should i use gulp ? what should my steps be.

The following, for example, worked for me from the angular project: pm2 start "ng serve --host"

tada: An Angular 2 Starter kit featuring Angular 2 (Router, Http, Forms, Services, Tests, E2E, To install PM2, run the following on your server:. In principle, it should be possible to compile, package, and then run that Angular2 application as a static application from AWS S3 bucket, GitHub or whatever static source. If I run Angular2 application on node server (with angular-cli "ng serve" command), it takes 500 MB of RAM on server - it's "Heey, common!"

PM2 to run with angular-cli application. for dev in preprod env create #file in angular folder application #default port 4200 and  AngularJS app is now successfully running in Angular 5 app, it is time to introduce a brand new page in Angular 5. We can just run a few Angular CLI command and create a component and a module.

To check that you have the npm client installed, run npm -v in a terminal/console window. Step 1: Install the Angular CLIlink. You use the Angular CLI to create  run ng --version. angular-cli: 1.0.0-beta.19-3 node: 6.7.0 os: win32 x64. Repro steps. created with Angular2 latest version seed project. Mention any other details that might be useful. So I am doing Angular2 / typescript / VS Code for sometime for a POC, I started using latest seed project from Angular2 website.

you'll learn how to deploy, monitor, debug, and scale a Node.js & Angular 2 web application on Google Cloud Platform. How will you use use this tutorial? Please run ng --version. If there's nothing outputted, please run in a Terminal: node --version and paste the result here: Repro steps. Was this an app that wasn't created using the CLI? What change did you do on your code? etc. The log given by the failure. Normally this include a stack trace and some more information.

  • I tried your method to run my application and have an error in pm2 log file. SyntaxError: missing ) after argument list
  • You can also do pm2 start $(which ng)
  • It works perfectly but uses lots of memory (I know this is not a problem but a simple application less than 100 lines uses more than 400mb). of course this is a problem of angular app. I think the best way is build app for production and make a simple sh file and run it
  • @Julien Moulin, is there any other way then .sh file? using exisitng .json file can we do this?
  • Your answer saved lot of time.
  • great answer, deserves more upvotes - works on latest pm2 version - although see the tweak I had to make to this in my answer
  • This answer doesn't really have anything to do with how to serve an angular2 app with pm2