Bun
Bun
A fast JS runtime, bundler, and package manager. An alternative to Node.js.
Bun
A fast JS runtime, bundler, and package manager. An alternative to Node.js.
Bun is a next-generation JavaScript/TypeScript runtime developed by Jarred Sumner in the Zig language. It was first released in 2022, and version 1.0 was released in September 2023. It is drawing attention for its start-up speed of up to 4 times faster than Node.js and its outstanding performance.
Bun's most notable feature is that it is an all-in-one tool. It includes not only a JavaScript runtime but also a package manager (replacing npm/yarn), a bundler (replacing webpack/esbuild), and a test runner, so you can start a project without installing separate tools.
Bun is based on the JavaScriptCore engine (used in Safari), and it has low memory usage and fast cold starts. It also natively supports Web APIs (fetch, WebSocket, ReadableStream, etc.) and is compatible with most Node.js APIs and npm packages.
In practice, Bun is used for fast builds in CI/CD pipelines, improving cold starts of serverless functions, and fast hot reload in development environments. In particular, TypeScript can be run directly without separate configuration, which greatly improves the developer experience (DX).
// 1. Bun으로 HTTP 서버 만들기 (내장 API)
const server = Bun.serve({
port: 3000,
fetch(request) {
const url = new URL(request.url);
if (url.pathname === "/api/hello") {
return Response.json({ message: "안녕하세요, Bun!" });
}
if (url.pathname === "/") {
return new Response("Welcome to Bun Server!", {
headers: { "Content-Type": "text/plain; charset=utf-8" }
});
}
return new Response("Not Found", { status: 404 });
}
});
console.log(`🚀 서버 실행 중: http://localhost:${server.port}`);
// 2. 파일 시스템 작업 (Bun API)
const file = Bun.file("./data.json");
const content = await file.json();
console.log("파일 내용:", content);
// 파일 쓰기 (동기적으로 빠르게 처리)
await Bun.write("./output.txt", "Bun으로 작성된 파일입니다!");
// 3. 패키지 설치 및 사용 (bun install이 npm보다 25배 빠름)
// $ bun install lodash
import _ from "lodash";
const users = [
{ name: "김철수", age: 30 },
{ name: "이영희", age: 25 },
{ name: "박민수", age: 35 }
];
const sorted = _.sortBy(users, "age");
console.log("나이순 정렬:", sorted);
// 4. TypeScript 직접 실행 (별도 설정 불필요!)
// $ bun run app.ts
interface User {
id: number;
name: string;
email: string;
}
const createUser = (name: string, email: string): User => ({
id: Date.now(),
name,
email
});
const newUser = createUser("홍길동", "hong@example.com");
console.log("새 사용자:", newUser);
"Our CI build takes 5 minutes, but switching to Bun can cut it to under 1 minute. Package installation is 25 times faster than npm, and TypeScript transpilation is built in, so the build pipeline becomes simpler."
"Bun uses the JavaScriptCore engine and is written in Zig, so it has better memory efficiency and start-up speed than Node.js, which is based on V8. It is compatible with most Node.js APIs, but it does not yet support some native modules, so compatibility must be verified before adopting it in production."
"Using Bun.file() and Bun.write() is more concise and faster than the fs module. In particular, JSON files can be parsed directly with file.json(), which also reduces the amount of code."
Take a mock interview on this topic → WIA SOOM AI Interview · Start for free
Native modules that use C++ bindings, such as bcrypt and canvas, may not work in Bun. Be sure to test dependency compatibility before switching to production.
Some Node.js-specific APIs, such as process.nextTick and require.resolve, may behave differently or may not be supported. Check the Node.js compatibility table in the official Bun documentation.
In production, adopt Bun first for development environments or build tools, and switch the runtime after verifying stability. bun run can execute package.json scripts as they are, so it is compatible with existing workflows.