Bun: This may just be the most exciting announcement this year for web development!

HRブログ
Ageless Dynasty
Published in
3 min readAug 3, 2022
Bun.png

So what is this new Javascript runtime and how does it compare to others like Node and Deno. Let’s dive into that…

What is Bun?

Bundle, transpile, install and run JavaScript & TypeScript projects — all in Bun. Bun is a new JavaScript runtime with a native bundler, transpiler, task runner and npm client built-in. — Official Bun Website.

Bun is an open-source project founded by Jarred Sumner, formerly a frontend engineer at Stripe. This Javascript runtime is an alternative to existing runtimes like Node, Deno, etc. It was built from scratch to focus on three main things:

  • Start fast (it has the edge in mind).
  • New levels of performance (extending JavaScriptCore, the engine).
  • Being a great and complete tool (bundler, transpiler, package manager).

Bun is designed as a drop-in replacement for your current JavaScript & TypeScript apps or scripts — on your local computer, server or on the edge. Bun natively implements hundreds of Node.js and Web APIs, including ~90% of Node-API functions (native modules), fs, path, Buffer, and more.

Why Bun?

The goal of Bun is to run most of the worlds JavaScript outside of browsers, bringing performance and complexity enhancements to your future infrastructure, as well as developer productivity through better, simpler tooling.

Bun promises exceptional performance, with its own benchmarks showing three times more HTTP requests per second than Node.js and nearly four times what Deno can deliver.

Server.png

You can find an additional benchmark tests at the top of the Bun website.

How does Bun work?

Bun.js uses the JavaScriptCore engine, which tends to start and perform a little faster than more traditional choices like V8. Bun is written in Zig, a low-level programming language with manual memory management under development, currently at version 0.9.1.

Most of Bun is written from scratch including the JSX/TypeScript transpiler, npm client, bundler, SQLite client, HTTP client, WebSocket client, and more.

Why is Bun fast?

The answer is different for every part of Bun, but one general theme: “Zig’s low-level control over memory and lack of hidden control flow makes it much simpler to write fast software,” says the Bun team.

Getting started

To setup a basic Bun app, you can run the following script in your terminal:

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

Bun’s HTTP server is built on web standards like Request and Response

// http.js
export default {
port: 3000,
fetch(request) {
return new Response("Welcome to Bun!");
},
};

Run it with bun:

bun run http.js

Then open http://localhost:3000 in your browser

--

--

Ageless Dynasty
Ageless Dynasty

Published in Ageless Dynasty

Babylon was the ancient city where some of the most influential empires of the ancient world ruled.

HRブログ
HRブログ

Written by HRブログ

Talks about #realworld, #finance , #economics, #crypto and #technology.