Skip to content

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.

ArgomentoAPI
Server HTTPBun.serve
Shell$
BundlerBun.build
I/O FileBun.file, Bun.write, Bun.stdin, Bun.stdout, Bun.stderr
Processi FiglioBun.spawn, Bun.spawnSync
Socket TCPBun.listen, Bun.connect
Socket UDPBun.udpSocket
WebSocketnew WebSocket() (client), Bun.serve (server)
TranspilerBun.Transpiler
RoutingBun.FileSystemRouter
HTML StreamingHTMLRewriter
HashingBun.password, Bun.hash, Bun.CryptoHasher, Bun.sha
SQLitebun:sqlite
Client PostgreSQLBun.SQL, Bun.sql
Client Redis (Valkey)Bun.RedisClient, Bun.redis
FFI (Foreign Function Interface)bun:ffi
DNSBun.dns.lookup, Bun.dns.prefetch, Bun.dns.getCacheStats
Testingbun:test
Workersnew Worker()
Module LoadersBun.plugin
GlobBun.Glob
CookiesBun.Cookie, Bun.CookieMap
Node-APINode-API
import.metaimport.meta
UtilityBun.version, Bun.revision, Bun.env, Bun.main
Sleep & TimingBun.sleep(), Bun.sleepSync(), Bun.nanoseconds()
Random & UUIDBun.randomUUIDv7()
Sistema & AmbienteBun.which()
Confronto & IspezioneBun.peek(), Bun.deepEquals(), Bun.deepMatch, Bun.inspect()
Elaborazione Stringhe e TestoBun.escapeHTML(), Bun.stringWidth(), Bun.indexOfLine
Utility URL e PercorsiBun.fileURLToPath(), Bun.pathToFileURL()
CompressioneBun.gzipSync(), Bun.gunzipSync(), Bun.deflateSync(), Bun.inflateSync(), Bun.zstdCompressSync(), Bun.zstdDecompressSync(), Bun.zstdCompress(), Bun.zstdDecompress()
Elaborazione StreamBun.readableStreamTo*(), Bun.readableStreamToBytes(), Bun.readableStreamToBlob(), Bun.readableStreamToFormData(), Bun.readableStreamToJSON(), Bun.readableStreamToArray()
Gestione Memoria e BufferBun.ArrayBufferSink, Bun.allocUnsafe, Bun.concatArrayBuffers
Risoluzione ModuliBun.resolveSync()
Parsing e FormattazioneBun.semver, Bun.TOML.parse, Bun.color
Basso Livello / InterniBun.mmap, Bun.gc, Bun.generateHeapSnapshot, bun:jsc

Bun a cura di www.bunjs.com.cn