Bun implementa un set di API native sull'oggetto globale Bun e attraverso una serie di moduli built-in. Queste API sono fortemente ottimizzate e rappresentano il modo canonico "nativo di Bun" per implementare alcune funzionalità comuni.
Bun si sforza di implementare le API Web standard ovunque possibile. Bun introduce nuove API principalmente per compiti lato server dove non esiste uno standard, come I/O file e avvio di un server HTTP. In questi casi, l'approccio di Bun si basa comunque su API standard come Blob, URL e Request.
ts
Bun.serve({
fetch(req: Request) {
return new Response("Success!");
},
});Clicca sul link nella colonna di destra per saltare alla documentazione associata.
| Argomento | API |
|---|---|
| Server HTTP | Bun.serve |
| Shell | $ |
| Bundler | Bun.build |
| I/O File | Bun.file, Bun.write, Bun.stdin, Bun.stdout, Bun.stderr |
| Processi Figlio | Bun.spawn, Bun.spawnSync |
| Socket TCP | Bun.listen, Bun.connect |
| Socket UDP | Bun.udpSocket |
| WebSocket | new WebSocket() (client), Bun.serve (server) |
| Transpiler | Bun.Transpiler |
| Routing | Bun.FileSystemRouter |
| HTML Streaming | HTMLRewriter |
| Hashing | Bun.password, Bun.hash, Bun.CryptoHasher, Bun.sha |
| SQLite | bun:sqlite |
| Client PostgreSQL | Bun.SQL, Bun.sql |
| Client Redis (Valkey) | Bun.RedisClient, Bun.redis |
| FFI (Foreign Function Interface) | bun:ffi |
| DNS | Bun.dns.lookup, Bun.dns.prefetch, Bun.dns.getCacheStats |
| Testing | bun:test |
| Workers | new Worker() |
| Module Loaders | Bun.plugin |
| Glob | Bun.Glob |
| Cookies | Bun.Cookie, Bun.CookieMap |
| Node-API | Node-API |
import.meta | import.meta |
| Utility | Bun.version, Bun.revision, Bun.env, Bun.main |
| Sleep & Timing | Bun.sleep(), Bun.sleepSync(), Bun.nanoseconds() |
| Random & UUID | Bun.randomUUIDv7() |
| Sistema & Ambiente | Bun.which() |
| Confronto & Ispezione | Bun.peek(), Bun.deepEquals(), Bun.deepMatch, Bun.inspect() |
| Elaborazione Stringhe e Testo | Bun.escapeHTML(), Bun.stringWidth(), Bun.indexOfLine |
| Utility URL e Percorsi | Bun.fileURLToPath(), Bun.pathToFileURL() |
| Compressione | Bun.gzipSync(), Bun.gunzipSync(), Bun.deflateSync(), Bun.inflateSync(), Bun.zstdCompressSync(), Bun.zstdDecompressSync(), Bun.zstdCompress(), Bun.zstdDecompress() |
| Elaborazione Stream | Bun.readableStreamTo*(), Bun.readableStreamToBytes(), Bun.readableStreamToBlob(), Bun.readableStreamToFormData(), Bun.readableStreamToJSON(), Bun.readableStreamToArray() |
| Gestione Memoria e Buffer | Bun.ArrayBufferSink, Bun.allocUnsafe, Bun.concatArrayBuffers |
| Risoluzione Moduli | Bun.resolveSync() |
| Parsing e Formattazione | Bun.semver, Bun.TOML.parse, Bun.color |
| Basso Livello / Interni | Bun.mmap, Bun.gc, Bun.generateHeapSnapshot, bun:jsc |