01
Primeiros passos
Hello World
O Bun executa JS/TS nativamente com um runtime baseado em Zig.
bun
console.log("Hello, World!");Run
O Bun é um substituto direto (drop-in) do node.
bun
# bun run main.ts
# bun main.tsServer
Bun.serve para servidores HTTP.
bun
export default {
port: 3000,
fetch(req) {
return new Response("Hello!");
}
};02
API
File I/O
Bun.file para leitura rápida de arquivos.
bun
const text = await Bun.file("file.txt").text();
const buf = await Bun.file("data.bin").arrayBuffer();SQLite
Suporte a SQLite embutido.
bun
import { Database } from "bun:sqlite";
const db = new Database("mydb.sqlite");
const query = db.query("SELECT * FROM users");
console.log(query.all());Hashing
Hashing de senhas embutido.
bun
const hash = await Bun.password.hash("secret");
const ok = await Bun.password.verify("secret", hash);Was this helpful?