Bun 1.0 is officially released, the explosive front-end runs at a much faster speed!

Article directory

  • 1. Baozi 1.0
  • 2. Bun is an all-in-one toolkit
    • Why do buns exist?
  • 2. Bun is a JavaScript runtime
    • Node.js compatibility
    • speed
    • TypeScript and JSX support
    • ESM and CommonJS compatibility
    • Web API
    • Hot reload
    • plug-in

1. Baozi 1.0

Bun 1.0 is finally here.

Bun is a fast, all-in-one toolkit for running, building, testing, and debugging JavaScript and TypeScript, from single files to full-stack applications. Today, Bun is stable and ready for production.

2. Bun is an all-in-one toolkit

We love JavaScript. It’s mature, growing rapidly, and its developer community is vibrant and passionate. it’s great.

However, since Node.js debuted 14 years ago, tools have been layered upon one another. Like any system that grows and evolves without centralized planning, JavaScript tools have become slow and complex.

Why do steamed buns exist

Bun’s goal is simple: eliminate slowness and complexity without giving up all the benefits of JavaScript. Your favorite libraries and frameworks should still work, and you don’t need to forget conventions you’re familiar with.
However, you need to forget about Bun’s many tools that make it unnecessary:
Node.js – Bun is a drop-in replacement for Node.js, so you don’t need:

  • node

  • npx-bunx 5 times faster

  • dotenv, cross-env-Bun.env reads files by default

  • nodemon, pm2-built-in viewing mode

  • ws – built-in WebSocket server

  • node-fetch, isomorphic-fetch – built-in fetch
    Transpiler – Bun can run .js, .ts, .cjs, .mjs, .jsx and .tsx files, which can replace:

  • tsc-(but you can keep it for type checking!)

  • babel, .babelrc,@babel/preset-*

  • ts-node,ts-node-esm

  • txx
    Bundler – Bun is a JavaScript bundler with best-in-class performance and an esbuild-compatible plugin API, so you don’t need:

  • esbuild

  • webpack

  • parcel,.parcelrc

  • rollup,rollup.config.js
    Package Manager – Bun is an npm-compatible package manager with familiar commands. It reads your package.json contents and writes to node_modules, just like other package managers, so you can replace:

  • npm, .npmrc,package-lock.json

  • yarn,yarn.lock

  • pnpm, pnpm.lock,pnpm-workspace.yaml

  • lerna
    Testing Library – Bun is a Jest-compatible test runner that supports snapshot testing, mocking, and code coverage, so you no longer need to:

  • jest,jest.config.js

  • ts-jest, @swc/jest,babel-jest

  • jest-extended

  • vitest,vitest.config.ts
    While these tools are (mostly) good on their own, using them together inevitably creates brittleness and a slow developer experience. They do a lot of redundant work; when you run jest, your code will be parsed 3+ times by various tools! The duct tape, inserts, and adapters needed to sew everything together always wear out eventually.

Bun is a single integration toolkit that avoids these integration issues. Every tool in the toolkit delivers a best-in-class developer experience, from performance to API design.

2. Bun is a JavaScript runtime

Bun is a fast JavaScript runtime. The goal is to make the experience of building software faster, less frustrating, and more fun.

Node.js Compatibility

Bun is a drop-in replacement for Node.js. This means that existing Node.js applications and npm packages can only run in Buns. Bun has built-in support for the Node API, including:

  • Built-in modules such as fs, path, and net,
  • Global variables such as __dirname and process,
  • and the Node.js module parsing algorithm. (e.g. node_modules)
    While perfect compatibility with Node.js is impossible – look at you node:v8 – Bun can run almost any Node.js application in the wild.

Bun is tested against the test suites of the most popular Node.js packages on npm. Server frameworks like Express, Koa, and Hono will work just fine. The same goes for applications built using the most popular full-stack frameworks. Collectively, these libraries and frameworks touch every important part of the Node.js API surface.

Full-stack applications built with Next.js, Remix, Nuxt, Astro, SvelteKit, Nest, SolidStart, and Vite are available in Buns.

Note – For a detailed breakdown of Node.js compatibility, check out: bun.sh/nodejs.

Speed

Bun is fast and starts up to 4x faster than Node.js. This difference is only amplified when running TypeScript files, which need to be transpiled to be run by Node.js.

Bun runs “hello world” TypeScript files 5x faster than esbuild with Node.js.

Unlike Node.js and other runtimes, which are built using Google’s V8 engine, Bun is built using Apple’s WebKit engine. WebKit is the engine that powers Safari, used on billions of devices every day. It’s fast, efficient, and battle-tested for decades.

TypeScript and JSX support

Bun has a JavaScript transpiler embedded in the runtime. This means you can run JavaScript, TypeScript, and even JSX/TSX files without dependencies.

bun index.ts
bun index.jsx
bun index.tsx

ESM and CommonJS compatibility

The transition from CommonJS to ES modules was slow and scary. After ESM was introduced, it took Node.js 5 years to support it without the –experimental-modules flag. Regardless, the ecosystem is still full of CommonJS.

Bun has always supported both module systems. Don’t worry about file extensions .jsvs .cjsvs .mjs , or including “type”: “module” in your package.json.

You can even use import and require(), in the same file. It just works.

import lodash from "lodash";
const _ = require("underscore");

Network API

Bun has built-in support for web standard APIs available in browsers, such as fetch, Request, Response, WebSocket, and ReadableStream.

const response = await fetch("https://example.com/");
const text = await response.text();

You no longer need to install packages like node-fetch and ws. Bun’s built-in Web API is implemented in native code, making it faster and more reliable than third-party alternatives.

Hot reload

Bun makes it easier for you as a developer to be more productive. You can run Bun with –hot to enable hot reload, which will reload your application when files change.

bun --hot server.ts

Unlike nodemon, a tool that hard restarts the entire process, Bun reloads the code without terminating the old process. This means that HTTP and WebSocket connections are not disconnected and state is not lost.

Plugin

Bun’s design is highly customizable.

You can define plugins to intercept imports and perform custom loading logic. Plugins can add support for other file types, such as .yaml or .png. The plugin API is inspired by esbuild, which means that most esbuild plugins only work in Bun.

import {<!-- --> plugin } from "bun";

plugin({<!-- -->
  name: "YAML",
  async setup(build) {<!-- -->
    const {<!-- --> load } = await import("js-yaml");
    const {<!-- --> readFileSync } = await import("fs");
    build.onLoad({<!-- --> filter: /.(yaml|yml)$/ }, (args) => {<!-- -->
      const text = readFileSync(args.path, "utf8");
      const exports = load(text) as Record<string, any>;
      return {<!-- --> exports, loader: "object" };
    });
  },
});