테스트 러너:bun test. Jest 호환 API(describe, test, expect). 추가 패키지 설치 불필요.
Bun 완벽 가이드 — Node.js보다 빠른 JavaScript 런타임 — 프로젝트 구조 다이어그램 (출처: 공식 문서 및 벤치마크 데이터 기반)
설치 및 첫 프로젝트 셋업
Bun은 curl 스크립트 한 줄로 설치된다. macOS, Linux, WSL을 지원한다. Windows 네이티브 지원은 v1.1부터 추가됐다.
Bun 완벽 가이드 — Node.js보다 빠른 JavaScript 런타임 — 기능 비교 차트 (출처: 공식 문서 및 벤치마크 데이터 기반)
Bun 설치 — macOS / Linux / Windows
# macOS / Linux / WSL
curl -fsSL https://bun.sh/install | bash
# Windows (PowerShell)
powershell -c "irm bun.sh/install.ps1 | iex"
# Homebrew (macOS)
brew install oven-sh/bun/bun
# 버전 확인
bun --version
# 예시 출력: 1.2.4
# 새 프로젝트 초기화
bun init my-app
cd my-app
# 패키지 설치 (npm install과 동일)
bun install
# TypeScript 파일 직접 실행 (tsc 불필요)
bun run index.ts
# 개발 서버 (파일 변경 시 자동 재시작)
bun --hot run index.ts
Bun HTTP 서버 — 빌트인 Bun.serve() API
// index.ts
const server = Bun.serve({
port: 3000,
async fetch(req) {
const url = new URL(req.url)
if (url.pathname === '/') {
return new Response('Hello from Bun!', {
headers: { 'Content-Type': 'text/plain' }
})
}
if (url.pathname === '/api/data') {
// SQLite 쿼리 (빌트인 bun:sqlite)
const db = new Database('app.db')
const rows = db.query('SELECT * FROM items LIMIT 10').all()
return Response.json(rows)
}
return new Response('Not Found', { status: 404 })
},
error(err) {
return new Response(`Error: ${err.message}`, { status: 500 })
}
})
console.log(`Server running at http://localhost:${server.port}`)
벤치마크 — Node.js, Deno와 실제 성능 비교
공식 벤치마크와 커뮤니티 측정치를 종합한 수치다 (2024년 기준, 하드웨어/워크로드에 따라 달라질 수 있음).