https://bun.sh
Bun — A fast all-in-one JavaScript runtime
Bundle, install, and run JavaScript & TypeScript — all in Bun. Bun is a new JavaScript runtime with a native bundler, transpiler, task runner, and npm client built-in.
Bun — A fast all-in-one JavaScript runtimeBun for Windows is here! Check out what's new in Bun 1.1 →DocsGuidesBlogDocsGuidesBlogBun v1.1.29 is here! →Bun is a fast JavaScriptall-in-one toolkit|Develop, test, run, and bundle JavaScript & TypeScript projects—all with Bun. Bun is an all-in-one JavaScript runtime & toolkit designed for speed, complete with a bundler, test runner, and Node.js-compatible package manager.Install Bun v1.1.29Linux & macOSWindowscurl -fsSL https://bun.sh/install | bashpowershell -c "irm bun.sh/install.ps1 | iex"View sourceBun.serve()WebSocketbun:sqliteServer-side rendering ReactHTTP requests per second (Linux x64)bun: 71,375 requests per second71,375deno: 38,445 requests per second38,445node: 14,525 requests per second14,525Bunv1.1Deno.serve()v1.42.1Node.js21.7.1View benchmarkWebSocket chat serverMessages sent per second (Linux x64, 32 clients)bun: 1,098,770 messages sent per second1,098,770deno: 471,040 messages sent per second471,040node: 179,186 messages sent per second179,186Bun.serve()v1.1Deno.serve()v1.42.1ws (Node.js)v21.7.1View benchmarkLoad a huge tableAverage queries per secondbun: 80.19 queries per second80.19deno: 35.73 queries per second35.73better-sqlite3: 21.29 queries per second21.29bun:sqlitev1.1deno (x/sqlite3)v1.42.1better-sqlite3Node v21.7.1View benchmark$ bun runBun is a JavaScript runtime.Bun is a new JavaScript runtime built from scratch to serve the modern JavaScript ecosystem. It has three major design goals:Speed. Bun starts fast and runs fast. It extends JavaScriptCore, the performance-minded JS engine built for Safari. Fast start times mean fast apps and fast APIs.Elegant APIs. Bun provides a minimal set of highly-optimized APIs for performing common tasks, like starting an HTTP server and writing files.Cohesive DX. Bun is a complete toolkit for building JavaScript apps, including a package manager, test runner, and bundler.Bun is designed as a drop-in replacement for Node.js. It natively implements hundreds of Node.js and Web APIs, including fs, path, Buffer and more.The goal of Bun is to run most of the world's server-side JavaScript and provide tools to improve performance, reduce complexity, and multiply developer productivity.Drop-in Node.js compatibilityBun aims to be a drop-in replacement for Node.js. It implements Node's module resolution algorithm, globals like Buffer and process, and built-in modules like fs and path. Click to track Bun's progress towards full compatibility.Fast running performanceBun extends the JavaScriptCore engine—the performance-minded JS engine built for Safari—with native-speed functionality implemented in Zig.Works with node_modulesWith Bun, you still use package.json to manage your dependencies. Use Bun's native npm client to see just how fast installing dependencies can be.No more module madnessForget the complicated rules around CommonJS, ESM, file extensions, resolution priority, and package.json configurations. With Bun, it just works.TypeScriptTypeScript is a first-class citizen in Bun. Directly execute .ts and .tsx files. Bun respects your settings configured in tsconfig.json, including "paths", "jsx", and more.Web-standard APIsBun implements the Web-standard APIs you know and love, including fetch, ReadableStream, Request, Response, WebSocket, and FormData.JSXJSX just works. Bun internally transpiles JSX syntax to vanilla JavaScript. Like TypeScript itself, Bun assumes React by default but respects custom JSX transforms defined in tsconfig.json.Watch modeThe bun run CLI provides a smart --watch flag that automatically restarts the process when any imported file changes.Cross-platform shell scriptsThe Bun.$ API implements a cross-platform bash-like interpreter, shell, and coreutils. This makes it easy to run shell scripts from JavaScript for devops tasks.The APIs you need. Baked in.Start an HTTP serverStart a WebSocket serverRead and write filesHash a passwordBundle for the browserWrite a testFile system routingRead a streamRun a shell scriptCall a C functionindex.tsxconst server = Bun.serve({ port: 3000, fetch(request) { return new Response("Welcome to Bun!"); }, }); console.log(`Listening on localhost:${server.port}`);index.tsxconst server = Bun.serve<{ authToken: string; }>({ fetch(req, server) { // use a library to parse cookies const cookies = parseCookies(req.headers.get("Cookie")); server.upgrade(req, { data: { authToken: cookies['X-Token'] }, }); }, websocket: { // handler called when a message is received async message(ws, message) { console.log(`Received: ${message}`); const user = getUserFromToken(ws.data.authToken); await db.Message.insert({ message: String(message), userId: user.id, }); }, }, }); console.log(`Listening on localhost:${server.port}`);index.tsxconst file = Bun.file(import.meta.dir + '/package.json'); // BunFile const pkg = await file.json(); // BunFile extends Blob pkg.name = 'my-package'; pkg.version = '1.0.0'; await Bun.write(file, JSON.stringify(pkg, null, 2)); index.tsxconst password = "super-secure-pa$$word"; const hash = await Bun.password.hash(password); // => $argon2id$v=19$m=65536,t=2,p=1$tFq+9AVr1bfPxQdh... const isMatch = await Bun.password.verify(password, hash); // => truebundle.tsxawait Bun.build({ entrypoints: ["./index.tsx"], outdir: "./build", minify: true, plugins: [ /* ... */ ] })index.tsximport { describe, expect, test, beforeAll } from "bun:test"; beforeAll(() => { // setup tests }); describe("math", () => { test("addition", () => { expect(2 + 2).toBe(4); expect(7 + 13).toMatchSnapshot(); }); }); index.tsxconst router = new Bun.FileSystemRouter({ style: "nextjs", dir: "/path/to/pages" }); const match = router.match("/blog/my-cool-post"); match.filePath; // "/path/to/pages/blog/[slug].tsx", match.kind; // "dynamic" match.params; // { slug: "my-cool-post" } index.tsxconst response = await fetch("https://bun.sh"); await Bun.readableStreamToArrayBuffer(response.body); // => ArrayBuffer await Bun.readableStreamToBlob(response.body); // => Blob await Bun.readableStreamToJSON(response.body); // => object await Bun.readableStreamToText(response.body); // => string await Bun.readableStreamToArray(response.body); // => unknown[] index.tsximport { $ } from 'bun'; // Run a shell command (also works on Windows!) await $`echo "Hello, world!"`; const response = await fetch("https://example.com"); // Pipe the response body to gzip const data = await $`gzip < ${response}`.arrayBuffer();index.tsximport { dlopen, FFIType, suffix } from "bun:ffi"; // `suffix` is either "dylib", "so", or "dll" depending on the platform const path = `libsqlite3.${suffix}`; const { symbols: { sqlite3_libversion, // the function to call }, } = dlopen(path, { sqlite3_libversion: { args: [], // no arguments returns: FFIType.cstring, // returns a string }, }); console.log(`SQLite 3 version: ${sqlite3_libversion()}`);$ bun installBun is an npm-compatible package manager.Bunpnpm17x slowernpm29x slowerYarn33x slowerInstalling dependencies from cache for a Remix app. View benchmarkNode.js compatibleBun still installs your dependencies into node_modules like npm and other package managers—it just does it faster. You don't need to use the Bun runtime to use Bun as a package manager.Crazy fastBun uses the fastest system calls available on each operating system to make installs faster than you'd think possible. WorkspacesWorkspaces are supported out of the box. Bun reads the workspaces key from your package.json and installs dependencies for your whole monorepo.Global install cacheDownload once, install anywhere. Bun only downloads a particular version of a package from npm once; future installations will copy it from the cache.Security by defaultUnlike other package managers, Bun doesn't execute postinstall scripts by default. Popular packages are automatically allow-listed; others can be added to the trustedDependencies in your package.json. Cross-platform package.json scriptsOn Windows, package.json scripts are powered by the Bun Shell. It's now safe to delete cross-env, rimraf and node-which.Familiar APIBun's CLI uses commands and flags that will feel familiar to any users of npm, pnpm, or yarn.Reads .npmrc & package-lock.jsonMigrate from npm without changing dependency versions. Try bun install secretly without telling your coworkers.Binary lockfileAfter installation, Bun creates a binary bun.lockb lockfile with the resolved versions of each dependency. The binary format makes reading and parsing much faster than JSON- or Yaml-based lockfiles.Replace yarn with bun install to get 30x faster package installs.Try it $ bun testBun is a test runner that makes the rest look like test walkers.BunVitest5x slowerJest+SWC8x slowerJest+tsjest18x slowerJest+Babel20x slower Running the test suite for ZodView benchmarkJest-compatible syntaxBun provides a Jest-style expect() API. Switch to bun test with no code changes.Crazy fastBun's fast startup times shine in the test runner. You won't believe how much faster your tests will run.Lifecycle hooksRun setup and teardown code per-test with beforeEach/afterEach or per-file with beforeAll/afterAll.ESM, TypeScript & JSX just workZero configuration needed to test TypeScript, ESM, and JSX files.Snapshot testingFull support for on-disk snapshot testing with .toMatchSnapshot(). Overwrite snapshots with the --update-snapshots flag.DOM APIsSimulate DOM and browser APIs in your tests using happy-dom.Watch modeUse the --watch flag to re-run tests when files change using Bun's instantaneous watch mode.Function mocksMock functions with mock() or spy on methods with spyOn().Replace jest with bun test to run your tests 10-30x faster.Try it 1Install Buncurl -fsSL https://bun.sh/install | bashpowershell -c "irm bun.sh/install.ps1 | iex"2Write your codeindex.tsxconst server = Bun.serve({ port: 3000, fetch(request) { return new Response("Welcome to Bun!"); }, }); console.log(`Listening on localhost:${server.port}`);3Run the filebun index.tsxbun index.tsxInstall BunQuick start Learn by example.Our guides break down how to perform common tasks with Bun.EcosystemBuild a frontend using Vite and BunView guide RuntimeInstall TypeScript declarations for BunView guide StreamsConvert a ReadableStream to a string with BunView guide EcosystemUse React and JSXUse EdgeDB with BunUse Prisma with BunCreate a Discord botAdd Sentry to a Bun appUse Drizzle ORM with BunRun Bun as a daemon with PM2Build an app with Nuxt and BunBuild an app with Qwik and BunBuild an app with Astro and BunBuild an app with Remix and BunRun Bun as a daemon with systemdBuild an app with Next.js and BunDeploy a Bun application on RenderBuild an app with SvelteKit and BunBuild a frontend using Vite and BunBuild an app with SolidStart and BunUse Neon Postgres through Drizzle ORMBuild an HTTP server using Hono and BunUse Neon's Serverless Postgres with BunBuild an HTTP server using Elysia and BunContainerize a Bun application with DockerBuild an HTTP server using Express and BunServer-side render (SSR) a React componentBuild an HTTP server using StricJS and BunRead and write data to MongoDB using Mongoose and BunHTTPCommon HTTP server usageHot reload an HTTP serverWrite a simple HTTP serverStart a cluster of HTTP serversConfigure TLS on an HTTP serverSend an HTTP request using fetchProxy HTTP requests using fetch()Stream a file as an HTTP ResponseUpload files via HTTP using FormDatafetch with unix domain sockets in BunStreaming HTTP Server with Async IteratorsStreaming HTTP Server with Node.js StreamsPackage managerAdd a dependencyAdd a Git dependencyAdd a peer dependencyAdd a tarball dependencyAdd a trusted dependencyAdd an optional dependencyAdd a development dependencyUsing bun install with ArtifactoryGenerate a human-readable lockfileMigrate from npm install to bun installConfiguring a monorepo using workspacesInstall a package under a different nameConfigure git to diff Bun's lockb lockfileInstall dependencies with Bun in GitHub ActionsOverride the default npm registry for bun installUsing bun install with an Azure Artifacts npm registryConfigure a private registry for an organization scope with bun installProcessesRead from stdinListen for CTRL+CListen to OS signalsSpawn a child processParse command-line argumentsRead stderr from a child processRead stdout from a child processGet the process uptime in nanosecondsSpawn a child process and communicate using IPCReading filesRead a JSON fileCheck if a file existsRead a file to a BufferRead a file as a stringGet the MIME type of a fileRead a file to a Uint8ArrayRead a file to an ArrayBufferWatch a directory for changesRead a file as a ReadableStreamRuntimeImport a JSON fileImport a TOML fileRun a Shell CommandRe-map import pathsSet a time zone in BunSet environment variablesImport a HTML file as textRead environment variablesDebugging Bun with the web debuggerInstall and run Bun in GitHub ActionsInstall TypeScript declarations for BunDebugging Bun with the VS Code extensionDefine and replace static globals & constantsStreamsConvert a ReadableStream to JSONConvert a Node.js Readable to JSONConvert a ReadableStream to a BlobConvert a Node.js Readable to a BlobConvert a ReadableStream to a BufferConvert a ReadableStream to a stringConvert a Node.js Readable to a stringConvert a ReadableStream to a Uint8ArrayConvert a ReadableStream to an ArrayBufferConvert a Node.js Readable to an Uint8ArrayConvert a Node.js Readable to an ArrayBufferConvert a ReadableStream to an array of chunksTest runnerMock functions in bun testSpy on methods in bun testUsing Testing Library with BunUpdate snapshots in bun testRun tests in watch mode with BunUse snapshot testing in bun testBail early with the Bun test runnerSkip tests with the Bun test runnerMigrate from Jest to Bun's test runnerRun your tests with the Bun test runnerSet the system time in Bun's test runnerWrite browser DOM tests with Bun and happy-domSet a per-test timeout with the Bun test runnerMark a test as a "todo" with the Bun test runnerRe-run tests multiple times with the Bun test runnerSet a code coverage threshold with the Bun test runnerGenerate code coverage reports with the Bun test runnerUtilitiesHash a passwordEscape an HTML stringGet the current Bun versionEncode and decode base64 stringsCheck if two objects are deeply equalDetect when code is executed with BunGet the directory of the current fileGet the file name of the current fileConvert a file URL to an absolute pathCompress and decompress data with gzipConvert an absolute path to a file URLGet the path to an executable bin fileSleep for a fixed number of millisecondsCompress and decompress data with DEFLATEGet the absolute path of the current fileCheck if the current file is the entrypointGet the absolute path to the current entrypointWebSocketBuild a simple WebSocket serverEnable compression for WebSocket messagesBuild a publish-subscribe WebSocket serverSet per-socket contextual data on a WebSocketWriting filesDelete a fileWrite to stdoutWrite a Blob to a fileWrite a file to stdoutAppend content to a fileWrite a string to a fileWrite a file incrementallyWrite a Response to a fileCopy a file to another locationWrite a ReadableStream to a fileResourcesDocsGuidesDiscordGitHubBlog ToolkitRuntimePackage managerTest runnerBundlerPackage runnerProjectBun 1.0Bun 1.1RoadmapContributingLicenseBaked with ❤️ in San FranciscoWe're hiring →
en
en
1727404202
https://bun.sh
Edit your site?
What are you doing?