Skip to main content

Finally something new in the JavaScript eco system.

After numerous years of getting to use Node.js, there’s finally competition. Bun is now publicly available. It describes itself as a quick all-in-one JavaScript runtime. similar to Node.js? — No, not like Node.js. there’s way more to the present story.

The role of Node.js today.

When I remember to after I first started writing code in JavaScript, it absolutely was an entire different world. JavaScript was utilized in browsers to form websites more interactive and modern. once you open a Webpage the JavaScript code must be interpreted by your browser, more specifically the JS engine of your browser. In Chromium based browsers this can be the V8 engine, in Safari the JavaScriptCore engine and in Firefox it’s SpiderMonkey. NodeJS used Google’s V8 engine to supply a JavaScript runtime environment for desktops and servers. during a nutshell: Node.js made it possible to execute JavaScript outside a browser. Sooner instead of later, more and more people started using JavaScript for backend development too.

Because there’s also a package-manager bundled with Node.js (npm — node package manager), which helps to manage external dependencies of your node projects, a complete JS eco system has grown around Node.js and npm within the last years. There are over 1.3 million packages available within the main npm registry. This makes it so comfortable to develop new software in JavaScript. there’s a library for pretty much anything you’ll imagine. — Why would you utilize something else?

What about Deno?

Maybe you’ve got heard a few Node.js competitor, released in 2020, named Deno. it’s also using Google’s V8 engine but is using an own package manager, which isn’t compatible with NPM packages. But it definitely has its strengths. Deno has sand boxing features, supports TypeScript out of the box and a solid collection of normal packages. Nevertheless, Deno has not yet been considered a true Node.js competition. the most important disadvantage is that the loss of the 1.5 million node packages. At the instant, there are only ~5000 Deno modules available. And there’s nothing else out of the normal that has convinced many users to think about Deno as a solid alternative to Node.js.

Bun has entered the chat.

Bun may be a newly released JavaScript runtime that, unlike Node.js and Deno use the JavaScriptCore engine and not the V8 engine. this can be one among the various reasons Bun claims to perform much faster than NodeJS and Deno. Additionally, Bun is written in Zig, a low-level artificial language wont to optimize every a part of Bun.

Bun is out there publically beta since early July 2022. But I’ve been a part of the closed beta already for quite few months. And yes, even in its beta, it makes JS development much faster and far more fun compared to Node.js. But that’s not simply because of its fastness. Bun is additionally a NPM client. it’s compatible with almost every npm package. you almost certainly understand how annoying it’s to attend for npm install to end. the answer is easy, with Bun you’ll not experience this. within the projects I tested it on, it had been often 2x faster than npm i and 1.6x faster than yarn.

Furthermore, Bun could be a JavaScript transpiler. It understands TypeScript and JSX out of the box. But what about bundling your files as an example with Webpack? — Bun also has its own JS bundler included. it’s blazing fast but lacks maybe some features for people using more advanced bundler features.

Bun’s biggest strength is that the performance gain while still supporting the bulk of NPM packages.

How to test Bun? — Create a React app with Bun

1.Install bun on mac (M1, x64), Linux (x64) or in WSL
curl https://bun.sh/install | bash
Always check script source before executing.

2.Create a new react project
bun create react ./bun-react-playground

3.Start the react app
cd bun-react-playground
bun dev

It took me 1182.02ms combined to create the project and run the dev server.

Check out the documentation and official website.

Is this the top of Node.js?

Not yet — it’s great to play with for private projects, but it’s not for businesses yet. there’s still a protracted journey, but I hope that more people use Bun as an alternate to Node.js within the future, so it gets the needed stability and support. Its performance and features are just on another level. My personal highlights are the following:

  • Bun automatically loads .env files
  • TypeScript & JSX just work (even .tsconfig support)
  • Web APIs like fetch & WebSocket are built-in (bye bye node-fetch

I use Bun for a few of my personal projects and that i enjoy it such a lot. there’s still some polishing work to try and do, but it’s already extremely stable and also the compatibility has been great on behalf of me to date. the sole thing I still need to use Node.js for is NestJS development because the NestCLI is using the node executable and there are some general issues.

Leave a Reply