skills/bun-guides-ecosystem-pm2/SKILL.md
Run Bun as a daemon with PM2
npx skillsauth add jarle/bun-skills Bun Run Bun as a daemon with PM2Install this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
PM2 is a popular process manager that manages and runs your applications as daemons (background processes).
It offers features like process monitoring, automatic restarts, and easy scaling. Using a process manager is common when deploying a Bun application on a cloud-hosted virtual private server (VPS), as it:
You can use PM2 with Bun in two ways: as a CLI option or in a configuration file.
--interpreterTo start your application with PM2 and Bun as the interpreter, open your terminal and run the following command:
pm2 start --interpreter ~/.bun/bin/bun index.ts
Alternatively, you can create a PM2 configuration file. Create a file named pm2.config.js 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, you can start your application with PM2
pm2 start pm2.config.js
That’s it! Your JavaScript/TypeScript web server is now running as a daemon with PM2 using Bun as the interpreter.
development
Using TypeScript with Bun, including type definitions and compiler options
development
Learn how to write tests using Bun's Jest-compatible API with support for async tests, timeouts, and various test modifiers
testing
Learn how to use snapshot testing in Bun to save and compare output between test runs
testing
Learn about Bun test's runtime integration, environment variables, timeouts, and error handling