Skip to main content

Run Bun as a daemon with PM2

还没翻译译自英文(bun.com)本页 10 段都还没译

PM2 is a process manager that runs your applications as daemons (background processes).

PM2 offers process monitoring, automatic restarts, and scaling. It 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

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

pm2 start --interpreter ~/.bun/bin/bun index.ts

With a configuration file

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

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.

pm2 start pm2.config.cjs

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

翻訳 © 2026 fanyi.dev · 原文 © 2026 the Bun project (LICENSE.md names no copyright holder) (MIT)