Node.js is Dead. — Long Live Bun.

Finally something new in the JavaScript eco system.

Yannis Burghardt
5 min readJul 27, 2022
cover image
Image Courtesy: Author

After so many years of having to use Node.js, there is finally competition. Bun is now publicly available. It describes itself as a fast all-in-one JavaScript runtime. Just like Node.js? — No, not like Node.js. There is much more to this story.

NodeJS logo
Image Courtesy: nodejs.dev

The role of Node.js today.

When I think back to when I first started writing code in JavaScript, it was a whole different world. JavaScript was used in browsers to make websites more interactive and modern. When 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 is the V8 engine, in Safari the JavaScriptCore engine and in Firefox it is SpiderMonkey. NodeJS used Google’s V8 engine to provide a JavaScript runtime environment for desktops and servers. In a nutshell: Node.js made it possible to execute JavaScript outside a browser. Sooner rather than later, more and more people started using JavaScript for backend development too.

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

Deno Logo
Image Courtesy: deno.land

What about Deno?

Maybe you have heard about a Node.js competitor, released in 2020, named Deno. It is also using Google’s V8 engine but is using an own package manager, which is not 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 standard packages. Nevertheless, Deno has not yet been considered a real Node.js competition. The biggest disadvantage is the loss of the 1.5 million node packages. At the moment, there are only ~5000 Deno modules available. And there is nothing else out of the ordinary that has convinced many users to consider Deno as a solid alternative to Node.js.

Bun Logo
Image Courtesy: bun.sh

Bun has entered the chat.

Bun is a newly released JavaScript runtime that, unlike Node.js and Deno use the JavaScriptCore engine and not the V8 engine. This is one of the many reasons Bun claims to perform much faster than NodeJS and Deno. Additionally, Bun is written in Zig, a low-level programming language used to optimize every part of Bun.

Bun is available in public beta since early July 2022. But I’ve been part of the closed beta already for quite a few months. And yes, even in its beta, it makes JS development much faster and much more fun compared to Node.js. But that is not just because of its execution speed. Bun is also a NPM client. It is compatible with almost every npm package. You probably know how annoying it is to wait for npm install to finish. The solution is simple, with Bun you will not experience this. In the projects I tested it on, it was often 2x faster than npm i and 1.6x faster than yarn.

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

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

Browser frame of new React app
Image Courtesy: Author

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 end of Node.js?

Not yet — It is great to mess around with for personal projects, but it is not for businesses yet. There is still a long journey, but I hope that more people use Bun as an alternative to Node.js in 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 some of my personal projects and I enjoy it so much. There is still some polishing work to do, but it is already extremely stable and the compatibility has been great for me so far. The only thing I still have to use Node.js for is NestJS development because the NestCLI is using the node executable and there are some general issues.

Interested in productivity apps?

Thanks for reading this! If you enjoyed this article make sure to leave a 👏, and if you need any other information or want to request a topic I should cover, feel free to drop a comment below!

You can also follow me on Twitter.

--

--

Yannis Burghardt

Computer science student who loves to code and learn new things. Here I share my tips and tricks on how to be more productive and efficient with technology.