DEV Community

Cover image for The bun is out πŸ₯Ÿ
Omher
Omher

Posted on

The bun is out πŸ₯Ÿ

πŸ‘‹πŸ½ Meet Bun: the brand new, all-in-one JavaScript runtime that can install npm packages faster than yarn and faster than npm and claims to be 3x faster than both Deno and node.js. Oh, last small fact it was all built by one person Jarred Sumner.

So, what is Bun?
A new JavaScript runtime, so you don't need any longer node.js, or Deno, so ahead and uninstall them for your system now, just kidding we will still need them for a while.
Bun just announced it's beta release and makes the claims that it's significantly faster that node.js and Deno.

unistall nodejs deno

But before we continue let's clarify something.

What is a JavaScript Runtime?

V8 engine

Let's think for a moment JavaScript by itself it's not very useful and it's needs to run thru an engine to convert it to machine code for a CPU.

The most popular JavaScript engine is google's V8, which powers chrome, node.js and Deno and makes execution very fast with JIT (Just in time compilation).

Now JavaScript together with the engine it's not very useful, we still something else, the developers want that the engine will provide a user-friendly API(WebSockets, file system and more). So JavaScript Runtime it's all this together(JavaScript engine and APIs), that only what is missing for the developers is to write JavaScript and it will run on this platforms.

🍞 So what it's so special with bun?

First they are talking about better performance, but how they actually make it so fast πŸ€”?

  • It doesn't use V8 😱, but instead use JavaScript Core from Webkit, this engine it's consider faster but more difficult to work with.

V8 JSCore

  • It's written in a low level programing language called zig, a relative new language similar to C or Rust.

  • Is all-in-one run time:

    • Native bundler to replace tools like webpack
    • Native transpiler, so you can write TS code out of the box
    • Will also transpile your JSX not supported yet?
    • Support node core modules import {readFile| from node:fs
    • Support node APIs, which allow to npm packages to also work in bun
    • Implements node's module resolution algorithm, which means you can install packages from npm into bun and this packages install much faster, like magic πŸͺ„.
    • Automatically loads environment variables from .env files. No more require("dotenv").load()
    • Own test runner, similar to Jest

πŸͺ„Installing npm packges feels like magic πŸͺ„
This is a small/medium project example

bun Vs npm

Sounds amazing, but remember this project it's on it's early days and there will be bugs πŸ›.

Resources

Bun

Thanks for reading

Top comments (0)