Nest: How use pm2 start nestjs Application ?

Created on 13 Apr 2018  路  6Comments  路  Source: nestjs/nest

$ pm2  logs

6|okoer-ap | 2018-04-13 17:04: [Nest] 19985   - 2018-04-13 17:04: 2018-4-13 17:04:37   2018-04-13 17:04: [RouterExplorer] 2018-04-13 17:04: Mapped {/:sku_id/suit/minus, PUT} route2018-04-13 17:04:  +0ms2018-04-13 17:04:
6|okoer-ap | 2018-04-13 17:04: [Nest] 19985   - 2018-04-13 17:04: 2018-4-13 17:04:37   2018-04-13 17:04: [RouterExplorer] 2018-04-13 17:04: Mapped {/:sku_id/changelog, GET} route2018-04-13 17:04:  +1ms2018-04-13 17:04:
6|okoer-ap | 2018-04-13 17:04: [Nest] 19985   - 2018-04-13 17:04: 2018-4-13 17:04:37   2018-04-13 17:04: [NestApplication] 2018-04-13 17:04: Nest application successfully started2018-04-13 17:04:  +1ms2018-04-13 17:04:

The log is very messy, The log time has appeared many times

Use nodemon to start the service, the log is normal

$  nodemon

[Nest] 21194   - 2018-4-13 17:13:03   [RouterExplorer] Mapped {/:sku_id/single/minus, PUT} route +0ms
[Nest] 21194   - 2018-4-13 17:13:03   [RouterExplorer] Mapped {/:sku_id/suit/plus, PUT} route +1ms
[Nest] 21194   - 2018-4-13 17:13:03   [RouterExplorer] Mapped {/:sku_id/suit/minus, PUT} route +0ms
[Nest] 21194   - 2018-4-13 17:13:03   [RouterExplorer] Mapped {/:sku_id/changelog, GET} route +0ms
[Nest] 21194   - 2018-4-13 17:13:03   [NestApplication] Nest application successfully started +1ms
type question 馃檶

Most helpful comment

use a ecosystem.config.js file, like this:

module.exports = {
  apps : [{
    name: 'serve-data-prod',
    script: 'dist/main.js',

    // Options reference: https://pm2.io/doc/en/runtime/reference/ecosystem-file/
    args: 'one two',
    instances: 1,
    autorestart: true,
    watch: false,
    max_memory_restart: '1G',
    env: {
      NODE_ENV: 'production'
    }
  }],

  deploy : {
    production : {
      user : 'node',
      host : '212.83.163.1',
      ref  : 'origin/master',
      repo : '[email protected]:repo.git',
      path : '/var/www/production',
      'post-deploy' : 'npm install && pm2 reload ecosystem.config.js --env production'
    }
  }
};

All 6 comments

Please use the issue template. I can't help you if you don't tell us how to reproduce.

@tomoat how are you launching. I'm using ts-node to launch via a package.json script e.g.

"start": "ts-node --type-check index.js"

I launch using pm2 via pm2 start npm -- start without issue.

Also, if you want to disable logging to avoid such a mess in the console output, here's a guide how to achieve it: https://docs.nestjs.com/v5/
(Techniques -> Logger)

incidentally for those using ecosystem:

{
    "script": "ts-node", // or locally "./node_modules/.bin/_ts-node" 
    "args": "src/main.ts"
}

use a ecosystem.config.js file, like this:

module.exports = {
  apps : [{
    name: 'serve-data-prod',
    script: 'dist/main.js',

    // Options reference: https://pm2.io/doc/en/runtime/reference/ecosystem-file/
    args: 'one two',
    instances: 1,
    autorestart: true,
    watch: false,
    max_memory_restart: '1G',
    env: {
      NODE_ENV: 'production'
    }
  }],

  deploy : {
    production : {
      user : 'node',
      host : '212.83.163.1',
      ref  : 'origin/master',
      repo : '[email protected]:repo.git',
      path : '/var/www/production',
      'post-deploy' : 'npm install && pm2 reload ecosystem.config.js --env production'
    }
  }
};

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JulianBiermann picture JulianBiermann  路  3Comments

cdiaz picture cdiaz  路  3Comments

artaommahe picture artaommahe  路  3Comments

anyx picture anyx  路  3Comments

rafal-rudnicki picture rafal-rudnicki  路  3Comments