A First Look at Bun: Will It Take Node’s Crown?
Bun is the newest and fastest all-in-one JavaScript framework. Will it take over Node? Is it better than Deno? Let's do some testing.
Join the DZone community and get the full member experience.
Join For FreeBun is a new and ambitious JavaScript toolset and runtime. Early adopters have been reporting that Bun is incredibly fast — so fast that it has been touted by some as a Node.js killer. Curious, I decided to check out Bun for myself and benchmark it against the competition.
Is it as fast as people are saying? How stable is it? Is it really better than Node? And can I use it with continuous integration?
What Is Bun?
Bun is the newest addition to the JavaScript runtime family. It has been making waves that rival those made by Deno when it came out in 2018. Bun sits in the space between Node and Deno. Bun, like Deno, supports TypeScript out of the box and offers developer-friendly features such as top-level awaits and built-in Web APIs. But, unlike Deno, Bun is intended to be a drop-in replacement for Node, Webpack, Babel, Yarn, and PostCSS — all in one neat package.
Plus, it has a really cute mascot.
Bun is released with an MIT and LGPL2 License (due to JavaScriptCore) and, at the time of writing, is on version v0.1.4.
How Does Bun Compare to Deno and Node?
While Bun is inspired by Node and Deno, it is also clearly attempting to improve development experience and productivity by providing a batteries-included toolset.
Bun takes features from Deno, like shipping as a single binary and having native TypeScript support.
Feature | Bun | Deno |
---|---|---|
TypeScript/TSX/JSX support | Yes | Yes |
Single executable | Yes | Yes |
Built-in test runner | Yes (in development) | Yes |
Built-in Web APIs (fetch, WebSocket, etc.) | Yes | Yes |
Top-level awaits | Yes | Yes |
npm compatibility | Yes | No |
Node compatibility | Yes | Partial |
tsconfig.json support | Yes | No |
WebAssembly support | Yes | Yes |
Built-in linter & formatter | No | Yes |
Permission system | No | Yes |
Package manifest format | package.json | N/A |
Module support | ES Modules, CommonJS | ES Modules |
License | MIT, LGPL2 | MIT |
JS Engine | JavaScriptCore | V8 |
Language | Zig, C++ | Rust, Tokio |
Compared to Node, Bun offers more features while striving to still be compatible:
Feature | Bun | Node |
---|---|---|
npm compatibility | Yes | Yes |
Node compatibility | Yes (beta) | Yes |
Single binary | Yes | No |
Built-in bundler & transpiler | Yes | No |
Native TypeScript support | Yes | No |
Package manifest format | package.json | package.json |
Lockfile format | Binary | JSON |
Native live-reload | Yes | No |
Built-in .env , .toml support |
Yes | No |
Top-level Awaits | Yes | Only on ES Modules |
JS Engine | JavaScriptCore | V8 |
Languages | Zig, C++ | C, C++ |
License | MIT, LGPL2 | MIT, BSD |
Being in the beta stage, however, means that Bun still has some quirks:
Documentation is limited, but Bun’s Discord is very active and a great source of knowledge.
No native Windows support (works with WSL, though)
Bun can get stuck while installing packages, fetch is not reliable, and, although it never happened to me, Bun can occasionally segfault.
Bun is not 100% compatible with Node yet. Not every npm package works. Express, for instance, is not yet functional.
Publishing to the npm registry does not work.
Various breaking changes will occur before the APIs and the CLI are stable.
Bun has a few distinct quality-of-life characteristics of its own:
Fast built-in sqlite3 module (MySQL and PostgreSQL are also planned)
Out-of-the-box
.env
,.toml
, and CSS support (no extra loaders required)Built-in framework support and optimizations for React and Next.js
Built-in Foreign Functions Interface (FFI) for low-level calls to ABI-supporting languages such as C, Rust, or Kotlin
Option to copy errors as Markdown (for rapid sharing)
Published at DZone with permission of Tomas Fernandez. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments