module
bun
The 'bun' module is where most of Bun's APIs are located. You can import all of the values and types in this module with an import statement, or by referencing the Bun global namespace.
Functions 49
- Bun.$()
The Bun shell is a powerful tool for running shell commands.
- Bun.allocUnsafe()
Allocate a new
Uint8Arraywithout zeroing the bytes. - Bun.build()
Bundles JavaScript, TypeScript, CSS, HTML and other supported files into optimized outputs.
- Bun.color()
Converts formats of colors
- Bun.concatArrayBuffers()
Concatenate an array of typed arrays into a single
ArrayBuffer. - Bun.connect()
Create a TCP client that connects to a server via a TCP socket
- Bun.deepEquals()
Fast deep-equality check two objects.
- Bun.deepMatch()
Returns true if all properties in the subset exist in the other and have equal values.
- Bun.deflateSync()
Compresses a chunk of data with
zlibDEFLATE algorithm. - Bun.escapeHTML()
Escape the following characters in a string.
- Bun.file()
Blobpowered by the fastest system calls available for operating on files. - Bun.fileURLToPath()
Convert a URL to a filesystem path.
- Bun.gc()
Manually trigger the garbage collector
- Bun.generateHeapSnapshot()
Show precise statistics about memory usage of your application
- Bun.gunzipSync()
Decompresses a chunk of data with
zlibGUNZIP algorithm. - Bun.gzipSync()
Compresses a chunk of data with
zlibGZIP algorithm. - Bun.indexOfLine()
Find the index of a newline character in potentially ill-formed UTF-8 text.
- Bun.inflateSync()
Decompresses a chunk of data with
zlibINFLATE algorithm. - Bun.inspect()
Pretty-print an object the same as console.log to a
string - Bun.listen()
Create a TCP server that listens on a port
- Bun.mmap()
Open a file as a live-updating
Uint8Arraywithout copying memory - Bun.nanoseconds()
Returns the number of nanoseconds since the process was started.
- Bun.openInEditor()
Open a file in your local editor.
- Bun.pathToFileURL()
Convert a filesystem path to a file:// URL.
- Bun.peek()
Extract the value from the Promise in the same tick of the event loop
- Bun.randomUUIDv5()
Generate a UUIDv5, which is a name-based UUID based on the SHA-1 hash of a namespace UUID and a name.
- Bun.randomUUIDv7()
Generate a UUIDv7, which is a sequential ID based on the current timestamp with a random component.
- Bun.readableStreamToArray()
Consume all data from a ReadableStream until it closes or errors.
- Bun.readableStreamToArrayBuffer()
Consume all data from a ReadableStream until it closes or errors.
- Bun.readableStreamToFormData()
Consume all data from a ReadableStream until it closes or errors.
- Bun.resolve()
Resolve a
moduleIdas though it were imported fromparent - Bun.resolveSync()
Synchronously resolve a
moduleIdas though it were imported fromparent - Bun.serve()
Bun.serve provides a high-performance HTTP server with built-in routing support.
- Bun.sha()
Hash
inputusing SHA-2 512/256 - Bun.sleep()
Resolve a
Promiseafter milliseconds. - Bun.sleepSync()
Sleep the thread for a given number of milliseconds
- Bun.sliceAnsi()
Slice a string by visible column width, preserving ANSI escape codes.
- Bun.spawn()
Spawn a new process
- Bun.spawnSync()
Spawn a new process
- Bun.stringWidth()
Get the column count of a string as it would be displayed in a terminal.
- Bun.stripANSI()
Remove ANSI escape codes from a string.
- Bun.udpSocket()
Create a UDP socket
- Bun.which()
Find the path to an executable, similar to typing which in your terminal.
- Bun.wrapAnsi()
Wrap a string to fit within the specified column width, preserving ANSI escape codes.
- Bun.write()
Use the fastest syscalls available to copy from
inputintodestination. - Bun.zstdCompress()
Compresses a chunk of data with the Zstandard (zstd) compression algorithm.
- Bun.zstdCompressSync()
Compresses a chunk of data with the Zstandard (zstd) compression algorithm.
- Bun.zstdDecompress()
Decompresses a chunk of data with the Zstandard (zstd) decompression algorithm.
- Bun.zstdDecompressSync()
Decompresses a chunk of data with the Zstandard (zstd) decompression algorithm.
Classes 26
- class Bun.Archive
A class for creating and extracting tar archives with optional gzip compression.
- class Bun.ArrayBufferSink
Fast incremental writer that becomes an ArrayBuffer on end().
- class Bun.Cookie
A class for working with a single cookie
- class Bun.CookieMap
A Map-like interface for working with collections of cookies.
- class Bun.CryptoHasher
Hardware-accelerated cryptographic hash functions
- class Bun.CryptoHashInterface
This class only exists in types
- class Bun.EventSource
EventTarget is a DOM interface implemented by objects that can receive events and may have listeners for them.
- class Bun.FileSystemRouter
- class Bun.Glob
Match files using glob patterns).
- class Bun.Image
Decode, transform and re-encode images.
- class Bun.MD4
This class only exists in types
- class Bun.MD5
This class only exists in types
- class Bun.RedisClient
- class Bun.S3Client
A configured S3 bucket instance for managing files.
- class Bun.SHA1
This is not the default because it's not cryptographically secure and it's slower than SHA512
- class Bun.SHA224
This class only exists in types
- class Bun.SHA256
This class only exists in types
- class Bun.SHA384
This class only exists in types
- class Bun.SHA512
This class only exists in types
- class Bun.SHA512_256
See also sha
- class Bun.SQL
Main SQL client interface providing connection and transaction management
- class Bun.Terminal
A pseudo-terminal (PTY) that can be used to spawn interactive terminal programs.
- class Bun.Transpiler
Quickly transpile TypeScript, JSX, or JS to modern JavaScript.
- class Bun.WebSocket
A WebSocket client implementation
- class Bun.WebView
A headless browser view for automation.
- class Bun.Worker
EventTarget is a DOM interface implemented by objects that can receive events and may have listeners for them.
Interfaces 117
- interface AbstractWorker
- interface AbstractWorkerEventMap
- interface AddEventListenerOptions
- interface ArchiveExtractOptions
Options for extracting archive contents.
- interface ArchiveOptions
Options for creating an Archive instance.
- interface BinaryTypeList
- interface BuildArtifact
A build artifact represents a file that was generated by the bundler
- interface BuildConfig
- interface BuildMetafile
Metafile structure containing build metadata for analysis.
- interface BuildOutput
The output of a build
- interface BunFile
Blobpowered by the fastest system calls available for operating on files. - interface BunInspectOptions
Options for
Bun.inspect - interface BunMessageEvent
A message received by a target object.
- interface BunPlugin
A Bun plugin.
- interface BunRegisterPlugin
Extend Bun's module resolution and loading behavior
- interface BunRequest
This Fetch API interface represents a resource request.
- interface CloseEventInit
- interface CompileBuildOptions
- interface CookieInit
- interface CookieStoreDeleteOptions
- interface CookieStoreGetOptions
- interface CronController
Controller object passed to the
scheduled()handler when a cron job fires. - interface CronJob
A handle to an in-process cron job returned by Bun.cron when called with a callback.
- interface CSRFGenerateOptions
- interface CSRFVerifyOptions
- interface CustomEventInit
- interface DirectUnderlyingSource
- interface DNSLookup
- interface EditorOptions
- interface Env
- interface ErrorEventInit
- interface ErrorLike
- interface EventInit
- interface EventListener
- interface EventListenerObject
- interface EventListenerOptions
- interface EventMap
- interface EventSourceEventMap
- interface FdSocketOptions
- interface FetchEvent
An event which takes place in the DOM.
- interface FileBlob
Blobpowered by the fastest system calls available for operating on files. - interface FileSink
Fast incremental writer for files and pipes.
- interface GenericTransformStream
- interface GlobScanOptions
- interface Hash
- interface HeapSnapshot
JavaScriptCore engine's internal heap snapshot
- interface HTMLBundle
Used when importing an HTML file at runtime or at build time.
- interface Import
- interface LibdeflateCompressionOptions
- interface MatchedRoute
- interface MessageEventInit
- interface MMapOptions
- interface NetworkSink
Fast incremental writer for files and pipes.
- interface OnLoadArgs
- interface OnLoadResultObject
- interface OnLoadResultSourceCode
- interface OnResolveArgs
- interface OnResolveResult
- interface PluginBuilder
The builder object passed to
Bun.plugin - interface PluginConstraints
- interface ReadableStreamDefaultReadManyResult
- interface RedisOptions
- interface ReservedSQL
Represents a reserved connection from the connection pool Extends SQL with additional release functionality
- interface ResourceUsage
- interface S3File
Represents a file in an S3-compatible storage service.
- interface S3FilePresignOptions
Options for generating presigned URLs
- interface S3ListObjectsOptions
- interface S3ListObjectsResponse
- interface S3Options
Configuration options for S3 operations
- interface S3Stats
- interface SavepointSQL
Represents a savepoint within a transaction
- interface Server
HTTP & HTTPS Server
- interface ServerWebSocket
A fast WebSocket designed for servers.
- interface SliceAnsiOptions
- interface Socket
Represents a TCP or TLS socket connection used for network communication.
- interface SocketAddress
- interface SocketHandler
- interface SocketListener
- interface SocketOptions
- interface SQLArrayParameter
Represents a SQL array parameter
- interface StringWidthOptions
- interface StructuredSerializeOptions
- interface Subprocess
A process created by Bun.spawn.
- interface SyncSubprocess
A process created by Bun.spawnSync.
- interface SystemError
- interface TCPSocket
Represents a TCP or TLS socket connection used for network communication.
- interface TCPSocketConnectOptions
- interface TCPSocketListener
- interface TCPSocketListenOptions
- interface TerminalOptions
Options for creating a pseudo-terminal (PTY).
- interface TLSOptions
Options for TLS connections
- interface TLSSocket
Represents a TCP or TLS socket connection used for network communication.
- interface TLSUpgradeOptions
- interface TransactionSQL
Represents a client within a transaction context Extends SQL with savepoint functionality
- interface TransformerFlushCallback
- interface TransformerStartCallback
- interface TransformerTransformCallback
- interface TranspilerOptions
- interface TSConfig
tsconfig.json options supported by Bun
- interface UnderlyingSink
- interface UnderlyingSinkAbortCallback
- interface UnderlyingSinkCloseCallback
- interface UnderlyingSinkStartCallback
- interface UnderlyingSinkWriteCallback
- interface UnderlyingSource
- interface UnderlyingSourceCancelCallback
- interface UnderlyingSourcePullCallback
- interface UnderlyingSourceStartCallback
- interface UnixSocketListener
- interface UnixSocketOptions
- interface WebSocketEventMap
- interface WebSocketHandler
Create a server-side ServerWebSocket handler for use with Bun.serve
- interface WhichOptions
- interface WorkerEventMap
- interface WorkerOptions
Bun's Web Worker constructor supports some extra options on top of the API browsers have.
- interface WrapAnsiOptions
- interface ZlibCompressionOptions
Compression options for
Bun.deflateSyncandBun.gzipSync
Types 79
- type $
- type ArchiveCompression
Compression format for archive output.
- type ArchiveInput
Input data for creating an archive.
- type ArrayBufferView
- type ArrayType
- type BeforeExitListener
- type BinaryType
- type BlobOrStringOrBuffer
- type BlobPart
- type BodyInit
- type BufferSource
- type BunLockFile
Types for
bun.lock - type BunLockFileBasePackageInfo
- type BunLockFilePackageArray
- type BunLockFilePackageInfo
- type BunLockFileWorkspacePackage
- type ColorInput
Valid inputs for color
- type CompressionFormat
Extends the standard web formats with
brotliandzstdsupport. - type CookieSameSite
- type CronWithAutocomplete
A cron schedule: a 5-field expression (
minute hour day month weekday) or a nickname. - type CSRFAlgorithm
- type DigestEncoding
- type DisconnectListener
- type DOMHighResTimeStamp
- type Encoding
- type EventListenerOrEventListenerObject
- type ExitListener
- type FFIFunctionCallable
- type FormDataEntryValue
- type HeadersInit
- type HMREvent
The event names for the dev server
- type HMREventNames
- type ImportKind
- type JavaScriptLoader
- type Loader
https://bun.com/docs/bundler/loaders
- type MacroMap
This lets you use macros as regular imports
- type MaybePromise
- type MessageEvent
- type MessageEventSource
- type MessageListener
- type MultipleResolveType
- type NullSubprocess
Utility type for any process from () with stdin, stdout, stderr all set to
nullor similar. - type NullSyncSubprocess
Utility type for any process from () with both stdout and stderr set to
nullor similar - type OnBeforeParseCallback
- type OnEndCallback
- type OnLoadCallback
- type OnLoadResult
- type OnResolveCallback
- type OnStartCallback
- type PathLike
- type PipedSubprocess
Utility type for any process from () with stdin, stdout, stderr all set to
"pipe". - type ReadableStreamController
- type ReadableStreamDefaultReadResult
- type ReadableStreamReader
- type ReadableSubprocess
Utility type for any process from () with both stdout and stderr set to
"pipe" - type ReadableSyncSubprocess
Utility type for any process from () with both stdout and stderr set to
"pipe" - type RejectionHandledListener
- type ServerWebSocketSendStatus
A status that represents the outcome of a sent message.
- type ShellExpression
- type SignalsListener
- type StringLike
- type StringOrBuffer
- type SupportedCryptoAlgorithms
- type Target
- type TimerHandler
- type Transferable
- type UncaughtExceptionOrigin
- type WarningListener
- type WebSocketCompressor
Compression options for WebSocket messages.
- type WebSocketOptions
Constructor options for the
Bun.WebSocketclient - type WebSocketOptionsCompression
- type WebSocketOptionsHeaders
- type WebSocketOptionsProtocolsOrProtocol
- type WebSocketOptionsProxy
- type WebSocketOptionsTLS
- type WebSocketReadyState
A state that represents if a WebSocket is connected.
- type WorkerType
- type WritableSubprocess
Utility type for any process from () with stdin set to
"pipe" - type XMLHttpRequestBodyInit
Variables 21
- const Bun.argv
The raw arguments passed to the process, including flags passed to Bun.
- const Bun.cron
- const Bun.embeddedFiles
A list of files embedded into the standalone executable.
- const Bun.enableANSIColors
Are ANSI colors enabled for stdin and stdout?
- const Bun.env
The environment variables of the process
- const Bun.fetch
- const Bun.hash
Hash a string or array buffer using Wyhash
- const Bun.isMainThread
Is the current global scope the main thread?
- const Bun.main
What script launched Bun?
- const Bun.password
Hash and verify passwords using argon2 or bcrypt.
- const Bun.plugin
- const Bun.redis
Default Redis client
- const Bun.revision
The git sha at the time the currently-running version of Bun was compiled
- const Bun.s3
A default instance of S3Client
- const Bun.secrets
Securely store and retrieve sensitive credentials using the operating system's native credential storage.
- const Bun.sql
SQL client
- const Bun.stderr
Write to stderr
- const Bun.stdin
Read from stdin
- const Bun.stdout
Write to stdout
- const Bun.version
The current version of Bun
- const Bun.version_with_sha
The current version of Bun with the shortened commit sha of the build
Namespaces 24
- namespace Bun.$
- namespace Bun.Build
- namespace Bun.CSRF
Generate and verify CSRF tokens
- namespace Bun.dns
DNS Related APIs
- namespace Bun.Image
- namespace Bun.inspect
- namespace Bun.JSON5
JSON5 related APIs
- namespace Bun.JSONC
JSONC related APIs
- namespace Bun.JSONL
JSONL (JSON Lines) related APIs.
- namespace Bun.markdown
Markdown related APIs.
- namespace Bun.Password
Hash and verify passwords using argon2 or bcrypt
- namespace Bun.peek
- namespace Bun.RedisClient
- namespace Bun.Security
bun installsecurity related declarations - namespace Bun.semver
Bun.semver provides a fast way to parse and compare version numbers.
- namespace Bun.Serve
- namespace Bun.Spawn
- namespace Bun.SQL
- namespace Bun.TOML
TOML related APIs
- namespace Bun.udp
- namespace Bun.unsafe
- namespace Bun.WebAssembly
- namespace Bun.WebView
- namespace Bun.YAML
YAML related APIs