What is Bun, the new hot thing in the Javascript world? Why is it so fast and can I use it for my projects?
Join the DZone community and get the full member experience.
In recent years, the web development landscape has discovered that, while super stylized websites and web applications with tons of very rich interactions made with Javascript might be appealing to users, the loading time of the page can be a hundred times more influential to the user’s perspective of the experience. As a result, there has been a ton of effort to reduce the loading time metrics of websites. Many frameworks and patterns have (re-)emerged to give solutions to this problem, like Server-Side Rendering and Static Site Generation.
Enter Jarred Sumner. Jarred noticed that an action as simple as printing to the console was extremely slow in Node.js. Here’s an example of the time it takes to execute a „Hello world“ program in Node.js and Rust.
Jarred said he was very bothered by this fact, as well as other realities from the Javascript world, like having to choose and harmonize multiple tools – the runtime, the bundler, the transpiler… He was sure this didn’t have to be the case and he set out on a one-man journey to build Bun.
The Bun is first and foremost a Javascript runtime like Node.js and Deno. It is designed to be a blazingly fast Javascript runtime. But don’t worry, embracing this new runtime does not mean having to refactor all of your existing code. Bun implements most of the Node APIs and Web APIs like fs, fetch, Buffer, WebSocket, and much more. Furthermore, Bun is also compatible with most NPM packages, even though it uses its own package manager, which is, again, built for speed.
But Bun is not just a Javascript runtime, it comes with batteries included. It comes with all the tools that are usually needed in a Javascript project: a package manager, a bundler, and a transpiler that not only works for Javascript, it also works for Typescript and JSX out-of-the-box.