bm2: A 2.8 MB pm2 Replacement Written in MoonBit
Today I'm sharing a tool I wrote, bm2, a pm2 replacement implemented in MoonBit.
Repository: https://github.com/chenbimo/bm2.
Some might wonder, pm2 works fine, why replace it?
Note: Due to time constraints, the tool doesn't yet offer online installation or updates. For discussion, please contact me at the end of the article.
Why replace pm2?
pm2 is a veteran process management tool in the Node ecosystem, and it's indeed easy to use.
But I only use a few commands daily, while pm2 has dozens of commands — 90% of its functionality I never touch.
So I thought, could I write something lighter and simpler myself?
Thus, bm2 was born.
What is bm2?
In one sentence: bm2 is a pm2 replacement, specifically designed to manage projects running on Node.js and Bun.js in a Linux environment.
It's written in the MoonBit language, and the entire tool consists of just two files — grab them and go.
How simple is it to use?
First, write a config file to tell it where your app is:
# bm2.toml
[[apps]]
name = "api"
cwd = "/srv/api"
script = "index.ts"
instances = 2
base_port = 3000
Then start it with a single command:
bm2 start
Done.
How lightweight is it?
These are real measurements from my local machine:
| Item | Data |
|---|---|
| bm2 binary size | 2.8 MB |
| Background service size | 3.0 MB |
| Resident memory | 2.7 MB |
| Command response | 3 ms |
One word: light.
The background service runs long-term, using less than 3 MB of memory — lighter than a web page.
Command response is 3 milliseconds, with no perceptible delay.
What can it do?
- Auto restart: If an app crashes, it pulls it back up immediately — no need to get up in the middle of the night to check logs.
- Memory protection: If an app exceeds its memory limit, it handles it automatically, preventing a bad app from dragging down the whole machine.
- Multi-instance execution: Run several instances of an app, with automatic port assignment, making it easy to simulate an online environment.
- Status viewing: See whether an app is alive or dead, how much memory it uses, and how long it's been running — all with one command:
- One-click stop: When you want to stop running, one command stops everything:
- Slip protection: For dangerous operations like stopping all apps, it asks for confirmation first.
- Update without interruption: Need to upgrade the background service? One command handles it, and your apps experience zero downtime throughout.
Why write it in MoonBit?
MoonBit is a relatively new programming language with very concise syntax.
How concise? Look at this example:
fn main {
println("Hello, bm2!")
}
Its advantages directly correspond to the data above.
- Small binary: MoonBit compiles into very compact binaries, so bm2 is only 2.8 MB.
- Fast execution: It compiles directly to machine code, so command response takes only 3 milliseconds.
- Memory efficient: No runtime overhead, so resident memory is only 2.7 MB.
- Simple syntax: It's comfortable to write, making it quick to add features and fix bugs, allowing bm2 to be continuously refined.
Honestly, using MoonBit to write this kind of small system-level tool is a very fitting combination.
Moreover, the MoonBit ecosystem is gradually growing — package management and build tools are quite complete, and the barrier to writing tools is getting lower and lower.
MoonBit Official Site https://www.moonbitlang.cn/
Final words
If you're also looking for a pm2 replacement — something lighter, simpler, and more worry-free for process management — give bm2 a try.
It's written in MoonBit, representing a real-world application of MoonBit in the system tools domain.
If this article was helpful, feel free to like, share, and comment to give me some support and encouragement. Thanks.
I wonder what you think? Feel free to leave a comment.
Thanks for reading. I'm Chen Suiyi, the Frontend Tiger. Public account 陈随易, personal website: https://chensuiyi.me.
Top 2 from juejin.cn, machine-translated. The original thread is authoritative.
Interesting. Now that I have AI, I'll use it to write one too.
Lightweight process management is really eye-catching.