Bun — Faster Javascript Runtime Than Node and Deno

Bun is trying to re-think the whole node ecosystem while bringing in backward compatibility of node packages...

Bun — Faster Javascript Runtime Than Node and Deno
Bun image

Bun is a new JavaScript runtime written from scratch that is faster than node and deno. Bun is still in its beta stages. Unlike node and deno which use the V8 engine bun uses the JavaScriptCore from WebKit which is generally faster and more memory efficient. Bun is written in ZIG which is a low programming language like Rust and C++.

Bun re-thinks the whole node package management structure of using node_modules to store all packages. You’ll just need to use bun, Instead of 1,000 node_modules for development. They are trying to achieve this by building into bun most of the necessary packages.  

Key Differences between Bun and Nodejs

  • Bun uses JavascriptCore from WebKit while Nodejs uses the V8 engine developed by Google. The V8 engine is slow compared to the JavascriptCore from WebKit.
  • Bun ships with built-in modules such as SQLite3 and JSX & TypeScript transpiler which are not available on Nodejs
  • Bun is 30x times faster during running programs compared to Nodejs.

Bun Features

  • Web API’s such as fetch, WebSocket, and ReadableStream are build into Bun.
  • Built from scratch JavaScript/TypeScript/JSX transpiler.
  • A JavaScript & CSS bundler
  • A Task runner for package.json scripts
  • A package manager that is compatible with NPM.

Getting started with Bun

To get started with bun you need to install bun using the bun install script.

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

In order to use bun command on the terminal add the following environment to your .bashrc in $HOME/.bashrc.

$HOME/.bashrc

# Bun environment variables

export BUN_INSTALL=\"$bun_install

export PATH=\"\$BUN_INSTALL/bin:\$PATH

Commands Overview

Installing packages:

bun install

Add package:

bun add react

Remove package:

bun remove react

React App With Bun:

bun dev # start dev server

Nextjs App with Bun:

bun dev # start dev server

Benchmark Overview

On Linux, bun installs packages 20x — 100x faster compared to npm install. On macOS, it’s more like 4x — 80x.

Bun performance image

Conclusion

Bun is fairly new and I wouldn’t recommend anyone to run it in production as it's still experimental and bugs are expected. However, the concepts are really solid. It feels like bun is trying to re-think the whole node ecosystem while bringing in backward compatibility of node packages. Would love to see what this projects morph into in the future.

Subscribe to Bluedoa Digest

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
alexander@example.com
Subscribe