Back to Home
    BunBun v1.1Intermediate

    Bun

    Runtime commands, package management, bundling, testing, and performance optimization.

    7 min read
    bunruntimejavascriptperformance

    Getting Started

    1 topic

    Project Setup

    Initialize and run projects with Bun

    bash
    # Create new project
    bun init
    
    # Run files directly
    bun run index.ts
    bun run index.js
    
    # Run scripts from package.json
    bun run dev
    bun run build
    
    # Install dependencies
    bun install
    bun add <package>
    bun add -d <package>  # Dev dependency
    bun remove <package>

    💡 Bun runs TypeScript natively, no config needed

    ⚡ bun install is significantly faster than npm

    Built-in APIs

    1 topic

    File & HTTP APIs

    Fast built-in APIs for common tasks

    typescript
    // File I/O
    const file = Bun.file("data.json");
    const text = await file.text();
    const json = await file.json();
    await Bun.write("output.txt", "Hello!");
    
    // HTTP Server
    Bun.serve({
      port: 3000,
      fetch(req) {
        const url = new URL(req.url);
        if (url.pathname === "/api") {
          return Response.json({ status: "ok" });
        }
        return new Response("Hello World!");
      },
    });
    
    // Password hashing
    const hash = await Bun.password.hash("secret");
    const valid = await Bun.password.verify("secret", hash);

    💡 Bun.file() is lazy - doesn't read until needed

    ⚡ Built-in server is faster than Express for simple APIs

    Testing

    1 topic

    Built-in Test Runner

    Write and run tests without extra dependencies

    typescript
    import { test, expect, describe } from "bun:test";
    
    describe("math", () => {
      test("addition", () => {
        expect(2 + 2).toBe(4);
      });
    
      test("async operation", async () => {
        const result = await fetchData();
        expect(result).toBeDefined();
        expect(result.status).toBe("ok");
      });
    });
    
    // Run tests
    // bun test
    // bun test --watch

    💡 Compatible with Jest-like syntax

    ⚡ Runs tests in parallel by default

    Related Articles

    Background reading and deeper explanations for this sheet.

    Generative AI Roadmap: A Practical, Beginner-Friendly Guide to Learning and Building Real Projects

    Generative AI can feel overwhelming, but you don’t need a PhD to get started and create useful applications. This roadmap breaks down what to learn, when to learn it, and how to apply each skill in real-world projects—from prompt engineering and APIs to RAG, evaluation, and production deployment.

    keyword overlap

    How to Host Small Models with Ollama on Your Local Machine (Beginner to Production)

    Want private, fast AI on your laptop without cloud costs? This practical guide shows you exactly how to host small models using Ollama in local machine setups, from installation to API integration and troubleshooting. You’ll get real commands, real-world examples, and a production-minded workflow you can use today.

    keyword overlap

    I Stopped Paying Monthly for a CRM. Here's What I Learned.

    But "self-hosted" isn't a single category — there's a huge range between a stripped-down open-source project you have to babysit and a polished, actively maintained product you can deploy in an afternoon. Here's how to think about the options, and one PHP/Laravel CRM worth putting on your shortlist.

    CRM and Sales

    keyword overlap

    Scaling AI APIs with FastAPI, Docker, and Load Balancers: A Practical Guide for Production

    Building an AI API is easy—keeping it fast and reliable under real traffic is the hard part. In this practical guide, you’ll learn how to scale FastAPI services with Docker and load balancers, from local setup to production architecture, with real-world examples, code, and deployment tips.

    keyword overlap