My first experience with Bun
When I learned about the latest Bun 1.2 release a few weeks ago, I decided to give it a try and to see how easily it is to convert one of our internal Typescript projects to use Bun instead of Node.js.
What is Bun?
According to their docs, Bun is "an all-in-one JavaScript runtime & toolkit designed for speed, complete with a bundler, test runner, and Node.js-compatible package manager".
The target project
We use Typescript via Node.js for an internal tool to manage server snapshots, e.g. create new snapshots and delete old ones. It is not the biggest code base which should keep the effort low to migrate it to Bun.
My goal of this task was, to find out how easy it is to replace Node.js and how much effort is needed to make the codebase compliant to Bun.
My Bun experience
Long story short: It took me less than 30 minutes to be able to run our tool with Bun.
The only change I had to apply to our code base was to switch the imports from Jest to Bun's Testrunner as I decided to go with Bun's internal Testrunner to minimize dependencies.
Here's what I did in detail:
- I downloaded the Bun binary from GitHub and stored it in /usr/local/bin.
- I set up a new project with Bun:
bun init
- I added all dependencies needed by our tool e.g.:
bun add tslog
- I added add dev-dependencies needed by our tool, e.g.:
bun add --dev @types/nodemailer
- In our tests, I switched the imports to:
import {expect, test, describe} from "bun:test";
Now, I can run our tool with the following command: bun run src/cli.ts create
while tests are run via: bun test
.
Feedback
So far, I had no issues with Bun. Transitioning from Node.js was easy, and Bun makes the transition process easy with their promise that Bun aims for 100% Node.js compatibility.
While I haven't seen much speed difference running our tool, installing dependencies is a lot faster. In total, we could reduce the CI pipeline execution by 58%.