01
시작하기
Hello World
Bun은 Zig 기반 런타임으로 JS/TS를 네이티브하게 실행합니다.
bun
console.log("Hello, World!");실행
Bun은 node를 그대로 대체할 수 있는 드롭인(drop-in) 대체제입니다.
bun
# bun run main.ts
# bun main.ts서버
Bun.serve로 HTTP 서버를 만듭니다.
bun
export default {
port: 3000,
fetch(req) {
return new Response("Hello!");
}
};02
API
파일 입출력
Bun.file로 빠르게 파일을 읽습니다.
bun
const text = await Bun.file("file.txt").text();
const buf = await Bun.file("data.bin").arrayBuffer();SQLite
SQLite를 기본 내장하고 있습니다.
bun
import { Database } from "bun:sqlite";
const db = new Database("mydb.sqlite");
const query = db.query("SELECT * FROM users");
console.log(query.all());해싱
비밀번호 해싱 기능이 내장되어 있습니다.
bun
const hash = await Bun.password.hash("secret");
const ok = await Bun.password.verify("secret", hash);Was this helpful?