DEV Community

Alex Spinov
Alex Spinov

Posted on

Bun Has a Free All-in-One API That Replaces Node, npm, and webpack

Bun is a JavaScript runtime, bundler, test runner, and package manager — all in one binary. It runs Node.js code 3-4x faster with zero configuration.

Package Manager (Replaces npm/yarn/pnpm)

bun install              # 10-100x faster than npm install
bun add express          # Add dependency
bun remove lodash        # Remove dependency
bun update               # Update all
Enter fullscreen mode Exit fullscreen mode

Runtime (Replaces Node.js)

bun run server.ts        # Run TypeScript directly — no tsc needed
bun run index.jsx        # Run JSX directly
Enter fullscreen mode Exit fullscreen mode

Built-in APIs

HTTP Server (No Express Needed)

Bun.serve({
  port: 3000,
  fetch(req) {
    const url = new URL(req.url);

    if (url.pathname === '/api/hello') {
      return Response.json({ message: 'Hello!' });
    }

    if (url.pathname === '/api/stream') {
      return new Response(
        new ReadableStream({
          start(controller) {
            controller.enqueue('chunk 1\n');
            controller.enqueue('chunk 2\n');
            controller.close();
          }
        })
      );
    }

    return new Response('Not found', { status: 404 });
  }
});
Enter fullscreen mode Exit fullscreen mode

File I/O (Fastest in Any Runtime)

// Write
await Bun.write('output.txt', 'Hello, Bun!');
await Bun.write('data.json', JSON.stringify({ key: 'value' }));

// Read
const text = await Bun.file('output.txt').text();
const json = await Bun.file('data.json').json();
const bytes = await Bun.file('image.png').arrayBuffer();
Enter fullscreen mode Exit fullscreen mode

SQLite (Built-in, No npm Package)

import { Database } from 'bun:sqlite';

const db = new Database('mydb.sqlite');
db.run('CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT)');
db.run('INSERT INTO users (name) VALUES (?)', ['Alice']);

const users = db.query('SELECT * FROM users').all();
Enter fullscreen mode Exit fullscreen mode

Test Runner (Replaces Jest/Vitest)

import { test, expect } from 'bun:test';

test('math works', () => {
  expect(2 + 2).toBe(4);
});

test('async works', async () => {
  const res = await fetch('http://localhost:3000/api/hello');
  expect(res.status).toBe(200);
});
Enter fullscreen mode Exit fullscreen mode
bun test                 # Run all tests
bun test --watch         # Watch mode
Enter fullscreen mode Exit fullscreen mode

Bundler (Replaces webpack/esbuild)

await Bun.build({
  entrypoints: ['./src/index.ts'],
  outdir: './dist',
  minify: true,
  splitting: true,
  target: 'browser'
});
Enter fullscreen mode Exit fullscreen mode

Why This Matters

  • One tool: Runtime + bundler + test runner + package manager
  • 3-4x faster: Than Node.js for most workloads
  • TypeScript native: No compilation step needed
  • Node compatible: Runs most npm packages unchanged

Need custom JavaScript tooling or performance optimization? I build developer tools and data pipelines. Check out my web scraping actors on Apify or reach out at spinov001@gmail.com for custom solutions.

Top comments (0)