English

Bun 2.0 has arrived with full Windows support and near-complete Node.js compatibility. It's now a serious contender for production workloads.

What's New in Bun 2.0

Native Windows Support

Finally, first-class Windows support:

# Install on Windows
powershell -c "irm bun.sh/install.ps1 | iex"

# Run your projects
bun run dev

99% Node.js Compatibility

Nearly all Node.js APIs now work:

  • fs, path, http, https
  • child_process, worker_threads
  • crypto (full OpenSSL compatibility) ✓
  • Native addons via N-API ✓

Performance Benchmarks

TaskNode.js 22Bun 2.0Improvement
Startup40ms8ms5x faster
HTTP Server50k req/s150k req/s3x faster
File I/O1.2 GB/s3.6 GB/s3x faster
Install Deps15s2s7.5x faster

Bun as a Complete Toolkit

Package Manager

# Install dependencies (faster than npm, yarn, pnpm)
bun install

# Add packages
bun add react next typescript

# Run scripts
bun run build

Bundler

// bun.build.ts
await Bun.build({
  entrypoints: ['./src/index.tsx'],
  outdir: './dist',
  minify: true,
  splitting: true,
  sourcemap: 'external',
});

Test Runner

// math.test.ts
import { expect, test, describe } from 'bun:test';

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

SQLite Built-in

import { Database } from 'bun:sqlite';

const db = new Database('app.db');
db.run('CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT)');

const users = db.query('SELECT * FROM users').all();

Bun with Next.js

Bun now works seamlessly with Next.js:

# Create Next.js app with Bun
bun create next-app my-app

# Run development server
cd my-app
bun run dev

Hot Module Replacement

Bun's HMR is incredibly fast:

// React component with instant HMR
export function Counter() {
  const [count, setCount] = useState(0);
  return <button onClick={() => setCount(count + 1)}>{count}</button>;
}

// Changes reflect in <10ms

Macros

Compile-time code execution:

// config.ts
export const config = {
  apiUrl: Bun.env.API_URL,
  buildTime: new Date().toISOString(),
} as const;

// main.ts - config is inlined at build time
import { config } from './config' with { type: 'macro' };
console.log(config.buildTime); // Becomes a static string

Migration from Node.js

  1. Install Bun globally
  2. Replace npm/yarn/pnpm with bun
  3. Replace node with bun
  4. Test thoroughly (some edge cases may differ)

Bun 2.0 is production-ready and worth considering for new projects and migrations.

0
0
0
0