Intro
What is Bun?
Installation
Quickstart
TypeScript
Templating
bun init
bun create
Runtime
bun run
File types
TypeScript
JSX
Environment variables
Bun APIs
Web APIs
Node.js compatibility
Single-file executable
Plugins
Watch mode
Module resolution
Auto-install
bunfig.toml
Debugger
Framework APISOON
Package manager
bun install
bun add
bun remove
bun update
bun publish
bun outdated
bun link
bun pm
Global cache
Workspaces
Lifecycle scripts
Filter
Lockfile
Scopes and registries
Overrides and resolutions
Patch dependencies
.npmrc support
Bundler
Bun.build
HTML & static sites
CSS
Fullstack Dev Server
Hot reloading
Loaders
Plugins
Macros
vs esbuild
Test runner
bun test
Writing tests
Watch mode
Lifecycle hooks
Mocks
Snapshots
Dates and times
DOM testing
Code coverage
Package runner
bunx
API
HTTP server
HTTP client
WebSockets
Workers
Binary data
Streams
SQL
S3 Object Storage
File I/O
import.meta
SQLite
FileSystemRouter
TCP sockets
UDP sockets
Globals
$ Shell
Child processes
HTMLRewriter
Hashing
Console
Cookie
FFI
C Compiler
Testing
Utils
Node-API
Glob
DNS
Semver
Color
Transpiler
Project
Roadmap
Benchmarking
Contributing
Building Windows
Bindgen
License
Search the docs...
/
Intro
What is Bun?
Installation
Quickstart
TypeScript
Templating
bun init
bun create
Runtime
bun run
File types
TypeScript
JSX
Environment variables
Bun APIs
Web APIs
Node.js compatibility
Single-file executable
Plugins
Watch mode
Module resolution
Auto-install
bunfig.toml
Debugger
Framework APISOON
Package manager
bun install
bun add
bun remove
bun update
bun publish
bun outdated
bun link
bun pm
Global cache
Workspaces
Lifecycle scripts
Filter
Lockfile
Scopes and registries
Overrides and resolutions
Patch dependencies
.npmrc support
Bundler
Bun.build
HTML & static sites
CSS
Fullstack Dev Server
Hot reloading
Loaders
Plugins
Macros
vs esbuild
Test runner
bun test
Writing tests
Watch mode
Lifecycle hooks
Mocks
Snapshots
Dates and times
DOM testing
Code coverage
Package runner
bunx
API
HTTP server
HTTP client
WebSockets
Workers
Binary data
Streams
SQL
S3 Object Storage
File I/O
import.meta
SQLite
FileSystemRouter
TCP sockets
UDP sockets
Globals
$ Shell
Child processes
HTMLRewriter
Hashing
Console
Cookie
FFI
C Compiler
Testing
Utils
Node-API
Glob
DNS
Semver
Color
Transpiler
Project
Roadmap
Benchmarking
Contributing
Building Windows
Bindgen
License
Bun natively supports TypeScript out of the box. All files are transpiled on the fly by Bun's fast native transpiler before being executed. Similar to other build tools, Bun does not perform typechecking; it simply removes type annotations from the file.
bun index.js
bun index.jsx
bun index.ts
bun index.tsx
Some aspects of Bun's runtime behavior are affected by the contents of yourtsconfig.json
file. Refer toRuntime > TypeScript page for details.
Bun supports.jsx
and.tsx
files out of the box. Bun's internal transpiler converts JSX syntax into vanilla JavaScript before execution.
functionComponent(props: {message:string}) {return ( <body> <h1style={{color:'red'}}>{props.message}</h1> </body> );}console.log(<Componentmessage="Hello world!" />);
Bun implements special logging for JSX to make debugging easier.
bun run react.tsx
<Component message="Hello world!" />
Text files can be imported as strings.
import textfrom"./text.txt";console.log(text);// => "Hello world!"
Hello world!
JSON and TOML files can be directly imported from a source file. The contents will be loaded and returned as a JavaScript object.
import pkgfrom"./package.json";import datafrom"./data.toml";
🚧Experimental
Bun has experimental support for WASI, theWebAssembly System Interface. To run a.wasm
binary with Bun:
bun ./my-wasm-app.wasm
# if the filename doesn't end with ".wasm"
bun run ./my-wasm-app.whatever
Note — WASI support is based onwasi-js. Currently, it only supports WASI binaries that use thewasi_snapshot_preview1
orwasi_unstable
APIs. Bun's implementation is not fully optimized for performance; this will become more of a priority as WASM grows in popularity.
You can import sqlite databases directly into your code. Bun will automatically load the database and return aDatabase
object.
import dbfrom"./my.db" with { type: "sqlite" };console.log(db.query("select * from users LIMIT 1").get());
This usesbun:sqlite
.
Support for additional file types can be implemented with plugins. Refer toRuntime > Plugins for full documentation.