sinProject-Inc/sinpro-dev

View on GitHub
docs/60-server/20-pm2.md

Summary

Maintainability
Test Coverage
---
title: PM2
description: PM2 is a daemon process manager that will help you manage and keep your application online 24/7.
---

[PM2](https://pm2.keymetrics.io/) is a daemon process manager that will help you manage and keep your application online 24/7.

[PM2 Quick Start >](https://pm2.keymetrics.io/docs/usage/quick-start/)

## Installation

```bash
npm install pm2@latest -g
```

## Starting

```bash
pm2 start app.js
```

## Monitoring

```bash
pm2 monit
```

## Microservice

list all processes:

```bash
pm2 list
```

display logs:

```bash
pm2 logs
```

Act on them:

```bash
pm2 stop [app_name | all]
pm2 restart [app_name | all]
pm2 delete [app_name | all]
```

## Troubleshooting

If the 'stop' or 'delete' commands do not work, execute the following command.

```bash
pm2 reload [app_name | all]
```

## Ecosystem File

```js:ecosystem.config.cjs
module.exports = {
    apps: [
        {
            name: 'sinpro-dev',
            script: 'build',
            interpreter: 'node',
            interpreterArgs: '--loader tsx',
            instances: '-1',
            exec_mode: 'cluster',
            watch: false,
            ignore_watch: ['logs'],
            env: {
                PORT: 3001,
            },
        },
    ],
}
```

```js:[talk]ecosystem.config.cjs
module.exports = {
    apps: [
        {
            name: 'talk',
            script: './server/index.ts',
            interpreter: 'node',
            interpreterArgs: '--loader tsx',
            instances: '-1',
            exec_mode: 'cluster',
            watch: false,
            ignore_watch: ['logs'],
            env: {
                PORT: 3002,
            },
        },
    ],
}
```

Start it easily:

```bash
pm2 start ecosystem.config.cjs
```

[More info >](https://pm2.keymetrics.io/docs/usage/application-declaration/)