Explore Bun.serve(), Bun.file(), bun:sqlite, bun:test, and what makes Bun significantly faster than Node.js for script startup
0 / 5 completed
1 / 5
How does Bun.serve() differ from Node.js's http.createServer()?
Bun.serve(): accepts a config object with a fetch(req) handler returning a Response — the same API as the Web standard fetch. Example: Bun.serve({ fetch(req) { return new Response('Hello') } }). It also supports websocket handlers in the same call. Benchmarks show it handles significantly more requests/second than Node.js's built-in HTTP module.
2 / 5
What is bun:sqlite and why is it notable?
bun:sqlite: is bundled with Bun — no external dependency. Usage: import { Database } from 'bun:sqlite'; const db = new Database('app.db'); const stmt = db.prepare('SELECT * FROM users WHERE id = ?'); stmt.get(1). The API is synchronous (SQLite is embedded), and Bun's implementation is benchmarked at several times faster than better-sqlite3.
3 / 5
How does Bun's bun:test test runner compare to Jest?
bun:test: implements the Jest API (describe, test, expect, mock, beforeEach) so existing Jest test files run without modification. Because Bun natively transpiles TypeScript and JSX, there is no Jest transform step. Bun's team reports 10–30x faster test runs on large suites, partly due to eliminating the Node.js + transpiler overhead.
4 / 5
What does Bun.file() return and how is it used?
Bun.file(): returns a BunFile — a Blob-compatible object. Reading is deferred: const file = Bun.file('data.json'); const data = await file.json(). You can also write files via Bun.write('output.txt', content). This API is more ergonomic than Node.js's fs.promises.readFile and aligns with the Web Blob standard.
5 / 5
What is Bun's primary speed advantage over Node.js for script startup time?
Bun speed: Bun uses Apple's JavaScriptCore engine (faster startup than V8) and is written in Zig for low-overhead system calls. It natively handles TypeScript, JSX, and ESM without invoking tsc or Babel, eliminating a compilation phase. This makes bun run script.ts notably faster than ts-node script.ts or even node --loader ts-node/esm.