Skip to content

Bun Cheatsheet

Fast all-in-one JavaScript runtime, bundler, and package manager.

01

Getting Started

Hello World

Bun runs JS/TS natively with Zig-based runtime.

bun
console.log("Hello, World!");

Run

Bun is a drop-in replacement for node.

bun
# bun run main.ts
# bun main.ts

Server

Bun.serve for HTTP servers.

bun
export default {
  port: 3000,
  fetch(req) {
    return new Response("Hello!");
  }
};
02

API

File I/O

Bun.file for fast file reading.

bun
const text = await Bun.file("file.txt").text();
const buf = await Bun.file("data.bin").arrayBuffer();

SQLite

Built-in SQLite support.

bun
import { Database } from "bun:sqlite";
const db = new Database("mydb.sqlite");
const query = db.query("SELECT * FROM users");
console.log(query.all());

Hashing

Built-in password hashing.

bun
const hash = await Bun.password.hash("secret");
const ok = await Bun.password.verify("secret", hash);

Was this helpful?