DevToolBoxGRATIS
Blog

Bun Package Manager: De Snelste JavaScript Runtime in 2026

12 minby DevToolBox

Bun is een alles-in-één JavaScript runtime en toolkit geschreven in Zig. De pakketbeheerder installeert afhankelijkheden tot 23x sneller dan npm.

Installatie en basiscommando's

Bun installeert in seconden en werkt als directe vervanging voor npm-commando's.

# Install Bun
curl -fsSL https://bun.sh/install | bash

# Verify installation
bun --version  # 1.x.x

# Install dependencies (reads package.json)
bun install

# Install a specific package
bun add express
bun add -d typescript @types/node   # dev dependency
bun add -g bunx                     # global install

# Remove a package
bun remove lodash

# Update all packages
bun update

# Run a script from package.json
bun run build
bun run dev

# Execute a TypeScript file directly (no transpile step)
bun run index.ts

Workspaces (monorepo-ondersteuning)

Bun ondersteunt npm-stijl workspaces voor monorepo's.

// package.json — monorepo root
{
  "name": "my-monorepo",
  "workspaces": [
    "packages/*",
    "apps/*"
  ],
  "scripts": {
    "dev": "bun run --filter '*' dev",
    "build": "bun run --filter '*' build",
    "test": "bun test"
  }
}

// Run a script only in specific workspace
bun run --filter @myapp/web dev

// Install a dependency in a specific workspace
bun add react --cwd apps/web

// Link a local workspace package
// (Bun automatically resolves workspace: protocol)

Het binaire lockbestand (bun.lockb)

Bun gebruikt een binair lockbestand in plaats van JSON.

# bun.lockb is a binary lockfile (much faster to parse than JSON)
# To view lockfile contents in human-readable form:
bun bun.lockb  # prints as yarn.lock format

# To regenerate lockfile:
bun install --frozen-lockfile  # CI: fails if lockfile is stale

# Migrating from npm/yarn/pnpm:
# Bun reads package-lock.json, yarn.lock, pnpm-lock.yaml
# to preserve existing versions on first install

# .gitignore for Bun:
# node_modules/
# *.lock  (optional — commit bun.lockb for reproducible installs)

Prestatiebenchmarks

Buns pakketbeheerder is aanzienlijk sneller dan alle alternatieven.

# Benchmark: installing react + 1400 packages
# (warm cache, MacBook M2 Pro)

npm install:   28.3s
yarn install:  14.1s
pnpm install:   9.4s
bun install:    1.2s   # 23x faster than npm!

# Cold cache (first install, no node_modules)
npm install:   38.7s
bun install:    4.1s   # 9x faster

# bun install uses:
# - Symlink-based node_modules (like pnpm)
# - Binary lockfile (bun.lockb) for fast parsing
# - Parallel downloads
# - Global package cache (~/.bun/install/cache)
# - Native code (written in Zig)

bunx en ingebouwde tools

bunx voert pakketten uit zonder download met gecachte binaries.

# bunx — like npx but instant (no download delay)
bunx create-next-app@latest my-app
bunx prettier --write .
bunx eslint src/

# Run TypeScript directly
bun index.ts            # works without ts-node or compilation
bun --watch server.ts   # auto-restart on file changes

# Bun's built-in test runner (Jest-compatible API)
bun test
bun test --watch
bun test src/utils.test.ts

// Example test file
import { expect, test, describe } from 'bun:test';

describe('math', () => {
    test('adds numbers', () => {
        expect(1 + 2).toBe(3);
    });

    test('async operations', async () => {
        const result = await fetch('https://api.example.com/data');
        expect(result.ok).toBe(true);
    });
});

Scripts en build-integratie

Bun voert package.json-scripts sneller uit dan npm/yarn.

// package.json scripts with Bun
{
  "scripts": {
    "dev": "bun --watch src/index.ts",
    "build": "bun build src/index.ts --outdir dist --target node",
    "bundle:web": "bun build src/app.ts --outdir public/js --target browser --minify",
    "test": "bun test",
    "lint": "bunx eslint src/",
    "format": "bunx prettier --write src/"
  }
}

// Bun's built-in bundler (replaces esbuild/webpack for simple cases)
// bun build src/index.ts --outdir dist --target node --minify

// Environment variables (Bun auto-loads .env files)
// No need for dotenv package!
console.log(process.env.DATABASE_URL); // works in Bun automatically

Bun vs npm vs pnpm vs Yarn

FeatureBunnpmpnpmYarn
Install speed (warm)1.2s28.3s9.4s14.1s
Lockfile formatBinaryJSONYAMLCustom text
node_modules styleSymlinksHoistedSymlinksHoisted/PnP
Workspace supportYesYesYesYes
Built-in TypeScriptYes (native)NoNoNo
Built-in test runnerYes (Jest API)NoNoNo
.env auto-loadingYesNoNoNo

Best practices

  • bun.lockb committen voor reproduceerbare installaties.
  • bun --watch gebruiken voor ontwikkeling.
  • Geleidelijk migreren van npm.
  • Voor monorepo's, Bun workspaces combineren met Turborepo.
  • Bun laadt .env automatisch — geen dotenv-pakket nodig.

Veelgestelde vragen

Is Bun productie-klaar in 2026?

Ja. Bun 1.0+ bereikte stabiliteit in 2023 met 99%+ Node.js API-dekking.

Werkt Bun met alle npm-pakketten?

Bijna alle. Uitzonderingen voor pakketten met native Node-addons.

Kan ik Bun gebruiken met Next.js?

Ja voor de pakketbeheerder — bun install werkt direct.

Hoe verschilt bun.lockb van package-lock.json?

bun.lockb is binair formaat dat in microseconden wordt geparseerd.

Bun of pnpm voor een nieuw project?

Beide zijn uitstekend. Bun voor alles-in-één aanpak, pnpm voor grote monorepo's.

Gerelateerde tools

𝕏 Twitterin LinkedIn
Was dit nuttig?

Blijf op de hoogte

Ontvang wekelijkse dev-tips en nieuwe tools.

Geen spam. Altijd opzegbaar.

Try These Related Tools

{ }JSON FormatterB→Base64 Encode OnlineIDUUID Generator Online

Related Articles

WebAssembly Gids 2026: Van Basis tot Productie met Rust, C++ en Go

Volledige WebAssembly-gids 2026: Rust, C++ en Go compileren naar WASM, JavaScript-integratie en prestatie-optimalisatie.

Monorepo Tools 2026: Turborepo vs Nx vs Lerna vs pnpm Workspaces

Volledige vergelijking van monorepo-tools 2026: Turborepo, Nx, Lerna en pnpm workspaces voor de juiste keuze.

TypeScript Type Guards: Complete Gids voor Runtime Type Checking

Beheers TypeScript type guards: typeof, instanceof, in en aangepaste guards.