diff options
author | 2023-10-12 02:52:43 +0530 | |
---|---|---|
committer | 2023-10-11 14:22:43 -0700 | |
commit | 4531cf18c223bd506a2c16d11fc3fd9fa6df6178 (patch) | |
tree | 480da3004fd4cadd8b42fa92e0984532a477f3db | |
parent | 31bda68f244955aef48fe41dc94e9a912f8698a6 (diff) | |
download | bun-4531cf18c223bd506a2c16d11fc3fd9fa6df6178.tar.gz bun-4531cf18c223bd506a2c16d11fc3fd9fa6df6178.tar.zst bun-4531cf18c223bd506a2c16d11fc3fd9fa6df6178.zip |
Docs : Added instructions to run bun apps in daemon (PM2) to address … (#5931)
* Docs : Added instructions to run bun apps in daemon (PM2) to address issue #4734
Added instructions to set bun as pm2 interpreter to extend same functionality as node.js apps.
* Add pm2 guide
* Add pm2 file
---------
Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>
-rw-r--r-- | docs/guides/ecosystem/pm2.md | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/docs/guides/ecosystem/pm2.md b/docs/guides/ecosystem/pm2.md new file mode 100644 index 000000000..c775c8ca3 --- /dev/null +++ b/docs/guides/ecosystem/pm2.md @@ -0,0 +1,54 @@ +--- +name: Run Bun as a daemon with PM2 +--- + +[PM2](https://pm2.keymetrics.io/) 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: + +- Keeps your Node.js application running continuously. +- Ensure high availability and reliability of your application. +- Monitor and manage multiple processes with ease. +- Simplify the deployment process. + +--- + +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, open your terminal and run the following command: + +```bash +pm2 start --interpreter ~/.bun/bin/bun index.ts +``` + +--- + +### With a configuration file + +--- + +Alternatively, you can create a PM2 configuration file. Create a file named `pm2.config.js` in your project directory and add the following content. + +```javascript +module.exports = { + name: "app", // Name of your application + script: "index.ts", // Entry point of your application + interpreter: "~/.bun/bin/bun", // Path to the Bun interpreter +}; +``` + +--- + +After saving the file, you can start your application with PM2 + +```bash +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. |