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. 

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 start 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 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 create react ./app
cd app
bun dev # start dev server

Nextjs App with Bun:

bun create next ./app
cd app
bun dev # start dev server

Benchmark Overview

On Linux, bun install install's 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 its 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's to in the future.