BUN, a new javaScript runtime environment.

Jahidul islam
3 min readJul 13, 2022

--

Bun.js logo

A new superhero we have in the web development playground, Let’s just say it is Flash from DC Comics or the Quick Silver from Marvel Comics in the web development domain, freshly released on the 5th of July. We all heard the names Node.js and Deno. Some of my novice developers/learners may not have heard about Deno. And some may ask what is node or deno. Let’s just break it first. Node.js is a JavaScript runtime environment written in c, c++. It uses googles V8 engine to tranpile javaScript. On the other hand, Bun uses Core JavaScript engine and it is written in the low-level language ZIG although it is relatively a new language but being low-level language it has some advantages over the higher-level languages. “Ryan Dahl” who is the original author of Node.js also wrote the Deno too. After releasing the Node.js he said in a conference that Node.js came out half-baked and at that state, it was not easy to rewrite the environment. It was slow as his speech. So instead of rewriting the Node.js, he wrote a new environment called Deno. For speed and convenience, he wrote the Deno in RUST. which came to be faster than Node.js. But there is a new player in the field ‘Bun’ claiming way faster than Deno. exactly to say that it is 3x faster than Node.js. We have to remember it is the creator‘s claim against no real-time reports yet.

Screenshot from bun.sh website

So now that we know Bun is faster than other competitors but is it versatile as others?

Yes! to my thought it is pretty versatile as it sounds. The key features for this would be :

1: Faster Runtime and Core JavaScript engine.

2: Node.js compatibility.

3: Node packages compatibility so that it can run node packages.

4: Built-in Typescript transpiler.

5: Environment files (.env) load without any hassle also there is no need to install the package Dot Env.

6: Bun.js natively supports Node.js core modules along with globals (Buffer, Process).

7: Built-in testing environment (like Jest), which claims to run testing super fast.

Installation

Now reading this much praise you may think let’s dive in. let’s install it and try it out. yes, you can do that, But a small piece of advice would be don't just ditch all the previous runtimes (Node/Deno). You may not like it or you may find some learning curve. Ok now come to the installation.

To install Bun.js at this time of writing the article you need a Unix-like system. Remember it is only a week old, so go easy on the newborn. For Mac Os and Linux Os, you only need a single line of code.

curl https://bun.sh/install | bash

Exactly this line of code.

Ok, now my Windows fellas gonna say what the heck dude where is the process for us. yes, there is a process for windows users and it is a little bit tedious, To install Bun.js right now on a windows machine you need WSL installed then you can use Bun.js on the machine. I know it sounds un-even, but remember, it is very early for the environment. hopefully, we will get an installer for windows very soon.

Post Installation

So now you have installed Bun.js how would you run/execute it in your project?

Nothing special just like node.js you can run some familiar commands to execute it. to run bun cli we need to type just below code.

bun run

This one command is for both the javascript project also for the Typescript project.

To install packages from the packages lists (package.json) we need to run:

bun install

it runs super fast, as the creator/website says 20x faster than node/npm.

Lastly to run testing just one command is all

bun wiptest

This is also for both javascript and typescript projects.

--

--