Bun

Bun APIs

Bun implements a set of native APIs on the Bun global object and through a number of built-in modules. These APIs are heavily optimized and represent the canonical "Bun-native" way to implement some common functionality.

Bun strives to implement standard Web APIs wherever possible. Bun introduces new APIs primarily for server-side tasks where no standard exists, such as file I/O and starting an HTTP server. In these cases, Bun's approach still builds atop standard APIs like Blob, URL, and Request.

Bun.serve({
  fetch(req: Request) {
    return new Response("Success!");
  },
});

Click the link in the right column to jump to the associated documentation.

TopicAPIs
HTTP ServerBun.serve
Shell$
BundlerBun.build
File I/OBun.file, Bun.write, Bun.stdin, Bun.stdout, Bun.stderr
Child ProcessesBun.spawn, Bun.spawnSync
TCP SocketsBun.listen, Bun.connect
UDP SocketsBun.udpSocket
WebSocketsnew WebSocket() (client), Bun.serve (server)
TranspilerBun.Transpiler
RoutingBun.FileSystemRouter
Streaming HTMLHTMLRewriter
HashingBun.password, Bun.hash, Bun.CryptoHasher, Bun.sha
SQLitebun:sqlite
PostgreSQL ClientBun.SQL, Bun.sql
Redis (Valkey) ClientBun.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
UtilitiesBun.version, Bun.revision, Bun.env, Bun.main
Sleep & TimingBun.sleep(), Bun.sleepSync(), Bun.nanoseconds()
Random & UUIDBun.randomUUIDv7()
System & EnvironmentBun.which()
Comparison & InspectionBun.peek(), Bun.deepEquals(), Bun.deepMatch, Bun.inspect()
String & Text ProcessingBun.escapeHTML(), Bun.stringWidth(), Bun.indexOfLine
URL & Path UtilitiesBun.fileURLToPath(), Bun.pathToFileURL()
CompressionBun.gzipSync(), Bun.gunzipSync(), Bun.deflateSync(), Bun.inflateSync(), Bun.zstdCompressSync(), Bun.zstdDecompressSync(), Bun.zstdCompress(), Bun.zstdDecompress()
Stream ProcessingBun.readableStreamTo*(), Bun.readableStreamToBytes(), Bun.readableStreamToBlob(), Bun.readableStreamToFormData(), Bun.readableStreamToJSON(), Bun.readableStreamToArray()
Memory & Buffer ManagementBun.ArrayBufferSink, Bun.allocUnsafe, Bun.concatArrayBuffers
Module ResolutionBun.resolveSync()
Parsing & FormattingBun.semver, Bun.TOML.parse, Bun.color
Low-level / InternalsBun.mmap, Bun.gc, Bun.generateHeapSnapshot, bun:jsc