DEV Community

Alexander for Chekiprice

Posted on • Originally published at blog.chekiprice.com on

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.

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
Enter fullscreen mode Exit fullscreen mode

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



Enter fullscreen mode Exit fullscreen mode

Commands Overview

Installing packages:

bun install
Enter fullscreen mode Exit fullscreen mode

Add package:

bun add react
Enter fullscreen mode Exit fullscreen mode

Remove package:

bun remove react
Enter fullscreen mode Exit fullscreen mode

React App With Bun:


bun create react ./app

cd app

bun dev # start dev server

Enter fullscreen mode Exit fullscreen mode

Documentation

Nextjs App with Bun:


bun create next ./app

cd app

bun dev # start dev server

Enter fullscreen mode Exit fullscreen mode

Documentation

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 image perfomance

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.

Top comments (0)