Bun is a new JavaScript & TypeScript runtime designed to be a faster, leaner, and more modern drop-in replacement for Node.js. ## Speed Bun is designed to start fast and run fast. It's transpiler and runtime are written in Zig, a modern, high-performance language. On Linux, this translates into startup times [4x faster](https://twitter.com/jarredsumner/status/1499225725492076544) than Node.js. {% image src="/images/bun-run-speed.jpeg" caption="Bun vs Node.js vs Deno running Hello World" /%} Performance sensitive APIs like `Buffer`, `fetch`, and `Response` are heavily profiled and optimized. Under the hood Bun uses the [JavaScriptCore engine](https://developer.apple.com/documentation/javascriptcore), which is developed by Apple for Safari. It starts and runs faster than V8, the engine used by Node.js and Chromium-based browsers. ## TypeScript 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. ```bash $ 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 your `tsconfig.json` file. Refer to [Runtime > TypeScript](/docs/runtime/typescript) page for details. ## JSX ## JSON and TOML Source files can import a `*.json` or `*.toml` file to load its contents as a plain old JavaScript object. ```ts import pkg from "./package.json"; import bunfig from "./bunfig.toml"; ``` ## WASM As of v0.5.2, experimental support exists for WASI, the [WebAssembly System Interface](https://github.com/WebAssembly/WASI). To run a `.wasm` binary with Bun: ```bash $ bun ./my-wasm-app.wasm # if the filename doesn't end with ".wasm" $ bun run ./my-wasm-app.whatever ``` {% callout %} **Note** — WASI support is based on [wasi-js](https://github.com/sagemathinc/cowasm/tree/main/packages/wasi-js). Currently, it only supports WASI binaries that use the `wasi_snapshot_preview1` or `wasi_unstable` APIs. Bun's implementation is not fully optimized for performance; this will become more of a priority as WASM grows in popularity. {% /callout %} ## Node.js compatibility Long-term, Bun aims for complete Node.js compatibility. Most Node.js packages already work with Bun out of the box, but certain low-level APIs like `dgram` are still unimplemented. Track the current compatibility status at [Ecosystem > Node.js](/docs/runtime/nodejs-apis). Bun implements the Node.js module resolution algorithm, so dependencies can still be managed with `package.json`, `node_modules`, and CommonJS-style imports. {% callout %} **Note** — We recommend using Bun's [built-in package manager](/docs/cli/install) for a performance boost over other npm clients. {% /callout %} ## Web APIs Some Web APIs aren't relevant in the context of a server-first runtime like Bun, such as the [DOM API](https://developer.mozilla.org/en-US/docs/Web/API/HTML_DOM_API#html_dom_api_interfaces) or [History API](https://developer.mozilla.org/en-US/docs/Web/API/History_API). Many others, though, are broadly useful outside of the browser context; when possible, Bun implements these Web-standard APIs instead of introducing new APIs. The following Web APIs are partially or completely supported. {% table %} --- - HTTP - [`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/fetch) [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request) [`Headers`](https://developer.mozilla.org/en-US/docs/Web/API/Headers) [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) --- - URLs - [`URL`](https://developer.mozilla.org/en-US/docs/Web/API/URL) [`URLSearchParams`](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams) --- - Streams - [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) [`WritableStream`](https://developer.mozilla.org/en-US/docs/Web/API/WritableStream) [`TransformStream`](https://developer.mozilla.org/en-US/docs/Web/API/TransformStream) [`ByteLengthQueuingStrategy`](https://developer.mozilla.org/en-US/docs/Web/API/ByteLengthQueuingStrategy) [`CountQueuingStrategy`](https://developer.mozilla.org/en-US/docs/Web/API/CountQueuingStrategy) and associated classes --- - Blob - [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) --- - WebSockets - [`WebSocket`](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket) --- - Encoding and decoding - [`atob`](https://developer.mozilla.org/en-US/docs/Web/API/atob) [`btoa`](https://developer.mozilla.org/en-US/docs/Web/API/btoa) [`TextEncoder`](https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder) [`TextDecoder`](https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder) --- - Timeouts - [`setTimeout`](https://developer.mozilla.org/en-US/docs/Web/API/setTimeout) [`clearTimeout`](https://developer.mozilla.org/en-US/docs/Web/API/clearTimeout) --- - Intervals - [`setInterval`](https://developer.mozilla.org/en-US/docs/Web/API/setInterval)[`clearInterval`](https://developer.mozilla.org/en-US/docs/Web/API/clearInterval) --- - Crypto - [`crypto`](https://developer.mozilla.org/en-US/docs/Web/API/Crypto) [`SubtleCrypto`](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto) [`CryptoKey`](https://developer.mozilla.org/en-US/docs/Web/API/CryptoKey) --- - Debugging - [`console`](https://developer.mozilla.org/en-US/docs/Web/API/console) [`performance`](https://developer.mozilla.org/en-US/docs/Web/API/Performance) --- - Microtasks - [`queueMicrotask`](https://developer.mozilla.org/en-US/docs/Web/API/queueMicrotask) --- - Errors - [`reportError`](https://developer.mozilla.org/en-US/docs/Web/API/reportError) --- - User interaction - [`alert`](https://developer.mozilla.org/en-US/docs/Web/API/Window/alert) [`confirm`](https://developer.mozilla.org/en-US/docs/Web/API/Window/confirm) [`prompt`](https://developer.mozilla.org/en-US/docs/Web/API/Window/prompt) (intended for interactive CLIs) --- - Realms - [`ShadowRealm`](https://github.com/tc39/proposal-shadowrealm) --- - Events - [`EventTarget`](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget) [`Event`](https://developer.mozilla.org/en-US/docs/Web/API/Event) [`ErrorEvent`](https://developer.mozilla.org/en-US/docs/Web/API/ErrorEvent) [`CloseEvent`](https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent) [`MessageEvent`](https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent) --- {% /table %} ## Bun APIs Bun exposes a set of Bun-specific APIs on the `Bun` global object and through a number of built-in modules. These APIs represent the canonical "Bun-native" way to perform some common development tasks. They are all heavily optimized for performance. Click the link in the left column to view the associated documentation. {% table %} - Topic - APIs --- - [HTTP](/docs/api/http) - `Bun.serve` --- - [File I/O](/docs/api/file-io) - `Bun.file` `Bun.write` --- - [Processes](/docs/api/spawn) - `Bun.spawn` `Bun.spawnSync` --- - [TCP](/docs/api/tcp) - `Bun.listen` `Bun.connect` --- - [Transpiler](/docs/api/transpiler) - `Bun.Transpiler` --- - [Routing](/docs/api/file-system-router) - `Bun.FileSystemRouter` --- - [HTMLRewriter](/docs/api/html-rewriter) - `HTMLRewriter` --- - [Utils](/docs/api/utils) - `Bun.peek` `Bun.which` --- - [SQLite](/docs/api/sqlite) - `bun:sqlite` --- - [FFI](/docs/api/ffi) - `bun:ffi` --- - [DNS](/docs/api/dns) - `bun:dns` --- - [Testing](/docs/api/test) - `bun:test` --- - [Node-API](/docs/api/node-api) - `Node-API` --- {% /table %} ## Plugins Support for additional file types can be implemented with plugins. Refer to [Runtime > Plugins](/docs/bundler/plugins) for full documentation. f16'>jarred/redo-zigstring-for-utf16 Unnamed repository; edit this file 'description' to name the repository.
aboutsummaryrefslogtreecommitdiff
path: root/integration/bunjs-only-snippets/macro-check.js (unfollow)
AgeCommit message (Expand)AuthorFilesLines
2022-03-17Update lockfile.zigGravatar Jarred Sumner 1-0/+16
2022-03-17Move `Bun` to JSC.APIGravatar Jarred Sumner 8-1420/+1667
2022-03-17lil helper methodGravatar Jarred Sumner 1-0/+8
2022-03-17Update build-idGravatar Jarred Sumner 1-1/+1
2022-03-17only check oncebun-v0.0.73Gravatar Jarred Sumner 1-42/+33
2022-03-17Add test coverage for emoji in blobsGravatar Jarred Sumner 1-84/+133
2022-03-17Prevent segfaultGravatar Jarred Sumner 1-0/+4
2022-03-17move some code aroundGravatar Jarred Sumner 3-189/+9
2022-03-17Update build-idGravatar Jarred Sumner 1-1/+1
2022-03-17optimize blob.text()Gravatar Jarred Sumner 1-83/+185
2022-03-17query_string_map -> urlGravatar Jarred Sumner 30-28/+405
2022-03-16Fix crash from checking if something is an object when it is undefinedbun-v0.0.72Gravatar Jarred Sumner 4-12/+12
2022-03-16Fix setTimeout on LinuxGravatar Jarred SUmner 1-5/+12
2022-03-16Increase from 4ms -> 40ms for timeoutGravatar Jarred SUmner 1-1/+1
2022-03-16Update README.mdGravatar Jarred Sumner 1-0/+1
2022-03-16llvm-stirp not workingGravatar Jarred Sumner 1-1/+0
2022-03-16Update MakefileGravatar Jarred Sumner 1-1/+1
2022-03-16Update Dockerfile.baseGravatar Jarred Sumner 1-0/+1
2022-03-16Update MakefileGravatar Jarred Sumner 1-2/+23
2022-03-16cleanup error printingGravatar Jarred Sumner 7-105/+193
2022-03-16Revert "Unlimited arguments in process.nextTick"Gravatar Jarred Sumner 1-38/+48
2022-03-16bun.lockbGravatar Jarred Sumner 3-0/+0
2022-03-16Update feature_flags.zigGravatar Jarred Sumner 1-0/+1
2022-03-16[bun.js] Bun.unsafe test should check the gcGravatar Jarred Sumner 1-4/+14
2022-03-16Update work_pool.zigGravatar Jarred Sumner 1-21/+28
2022-03-16Add a way to run serial tasks on a different threadGravatar Jarred Sumner 1-3/+65
2022-03-16fix crash when SyntaxError is thrown and we did not receive an ErrorInstance?Gravatar Jarred Sumner 1-18/+25
2022-03-16[bun.js] Fix release-mode test failures in HeadersGravatar Jarred Sumner 1-47/+42
2022-03-16Update ref_count.zigGravatar Jarred Sumner 1-2/+0
2022-03-15file is too bigjarred/replGravatar Jarred Sumner 1-113827/+0
2022-03-15Update Dockerfile.baseGravatar Jarred Sumner 1-1/+1
2022-03-15Add rust and lolhtml to dockerfileGravatar Jarred Sumner 2-0/+20
2022-03-15bump webkitGravatar Jarred Sumner 1-1/+1
2022-03-15Update WebKitGravatar Jarred Sumner 1-0/+0
2022-03-15:camera:Gravatar Jarred Sumner 60-799/+859
2022-03-15Fix test failureGravatar Jarred Sumner 1-15/+17
2022-03-15[bun:error] handle errors without a name or messageGravatar Jarred Sumner 1-6/+11
2022-03-15Update pool.zigGravatar Jarred Sumner 1-0/+1
2022-03-15Load .env by defaultGravatar Jarred Sumner 2-0/+8
2022-03-15mimalloc interpose is buggyGravatar Jarred Sumner 1-2/+25
2022-03-15higher max http requests for bun.jsGravatar Jarred Sumner 1-0/+29
2022-03-15zero copyGravatar Jarred Sumner 1-21/+15
2022-03-15Update javascript.zigGravatar Jarred Sumner 1-2/+0
2022-03-15[bun.js] utf8 console.{time, count, timeEnd, profile, profileEnd, count, cou...Gravatar Jarred Sumner 1-16/+16