# Run Bun as a daemon with PM2 (/docs/guides/ecosystem/pm2)

<!-- agent-signals: reading_time_min: 1 · est_tokens: 323 · updated: 2026-07-28 -->
Related: [Build an app with Astro and Bun](/docs/guides/ecosystem/astro.md), [Create a Discord bot](/docs/guides/ecosystem/discordjs.md), [Containerize a Bun application with Docker](/docs/guides/ecosystem/docker.md), [Use Drizzle ORM with Bun](/docs/guides/ecosystem/drizzle.md), [Use Gel with Bun](/docs/guides/ecosystem/gel.md), [Build an HTTP server using Elysia and Bun](/docs/guides/ecosystem/elysia.md)

[PM2](https://pm2.keymetrics.io/) is a process manager that runs your applications as daemons (background processes).

It offers process monitoring, automatic restarts, and scaling, and keeps your application running when you deploy it to a cloud-hosted virtual private server (VPS).

***

You can use PM2 with Bun in two ways: as a CLI option or in a configuration file.

### With `--interpreter` [#with---interpreter]

To start your application with PM2 and Bun as the interpreter, run:

```bash terminal icon="terminal"
pm2 start --interpreter ~/.bun/bin/bun index.ts
```

***

### With a configuration file [#with-a-configuration-file]

Alternatively, create a file named `pm2.config.js` in your project directory and add the following content.

```js pm2.config.js icon="file-code"
module.exports = {
  name: "app", // Name of your application
  script: "index.ts", // Entry point of your application
  interpreter: "bun", // Bun interpreter
  env: {
    PATH: `${process.env.HOME}/.bun/bin:${process.env.PATH}`, // Add "~/.bun/bin/bun" to PATH
  },
};
```

***

After saving the file, start your application with PM2.

```bash terminal icon="terminal"
pm2 start pm2.config.js
```

***

Your JavaScript/TypeScript web server now runs as a daemon with PM2, using Bun as the interpreter.
