Accelerate JS/TS Development with Bun
A Bun runtime skill covering setup, package management, built-in APIs, testing, bundling, and Node.js migration.
Why it matters
Leverage the Bun runtime to significantly boost development speed for JavaScript and TypeScript projects. This asset helps you start new projects, migrate from Node.js, and optimize your build and test processes.
Outcomes
What it gets done
Initialize new projects with Bun, including TypeScript and JSX support.
Manage packages efficiently using Bun's fast installer and updater.
Utilize Bun's built-in bundler, test runner, and HTTP server.
Troubleshoot and optimize Bun-specific development workflows.
Install
Add it to your toolbox
Run in your project directory:
curl -fsSL https://spark.entire.vc/get/ag-bun-development | bash Overview
Bun Development
A Bun runtime skill covering project setup, package management, built-in APIs (file system, HTTP/WebSocket server, SQLite, password hashing), testing, bundling, and Node.js migration. Use when starting a new Bun project, migrating from Node.js, or optimizing performance with Bun-native APIs instead of Node-compatibility equivalents.
What it does
Bun installs via brew install oven-sh/bun/bun, the official install script from bun.sh, or npm install -g bun, and updates in place with bun upgrade. Its value over Node.js: faster startup (~25ms vs Node's ~100ms+), 10-100x faster package installs, native TypeScript and JSX support with no separate transpiler, and a built-in test runner and bundler where Node relies on external tools (Jest/Vitest, Webpack/esbuild). This skill covers Bun as a JavaScript/TypeScript runtime end to end. Project setup runs TypeScript directly with no build step, initializes new projects (package.json, tsconfig.json, index.ts, README) with optional templates, and manages packages with bun install/bun add/bun remove/bun update, bunx as an npx equivalent that can run a package binary without installing it, and a fast binary bun.lockb lockfile (with a text-lockfile export for debugging, or trusting an existing lockfile). Running code covers direct TypeScript/JavaScript execution, package.json scripts, watch mode with auto-restart or hot reload, automatic .env file loading with variables exposed via Bun.env (or the Node-compatible process.env), and running with a specific env file via --env-file.
Built-in APIs replace common Node.js dependencies: Bun.file()/Bun.write() read and write files (as text, JSON, or an array buffer, with streaming for large files) faster than the fs/promises equivalent; Bun.serve() runs an HTTP server via a fetch(request) handler returning Response/Response.json(), with an error() handler for uncaught errors; the same Bun.serve() upgrades a request to a WebSocket connection with open/message/close handlers; bun:sqlite's Database class runs SQLite queries with prepared statements (db.prepare(...).run()/.get()/.query(...).all()); and Bun ships built-in password hashing. Testing uses Bun's own test runner (bun test, with file/pattern filtering, watch mode, coverage, and timeouts) with its own matchers and mocking support - no separate test framework needed. Bundling (bun build) compiles for production, and Bun can compile a project to a standalone executable, including cross-compilation and embedded assets.
Migrating from Node.js is largely compatible out of the box - fs, path, crypto, the global process, Buffer, __dirname, and __filename all work unmodified - but require() should become import, require.resolve() becomes import.meta.resolve(), process.hrtime() becomes Bun.nanoseconds(), and setImmediate() becomes queueMicrotask(). Common migration steps: install Bun, delete node_modules/package-lock.json and run bun install, update package.json scripts ("start": "node index.js" to "bun run index.ts", "test": "jest" to "bun test"), and add @types/bun.
When to use - and when NOT to
Use this when starting a new JS/TS project with Bun, migrating an existing Node.js project to Bun, optimizing development speed, using Bun's built-in bundler or test runner, or troubleshooting Bun-specific issues.
For performance, prefer Bun-native APIs over their Node-compatibility equivalents: Bun.file() over fs/promises, and Bun.serve() over Express/Fastify (claimed 4-10x faster) or a Bun-optimized framework like Elysia; always bundle and minify for production with bun build ./src/index.ts --outdir ./dist --minify --target node rather than shipping unbundled source.
Inputs and outputs
Input is a JS/TS project or a specific development task (install a package, run a server, write a test, migrate from Node). Output is Bun-native code and CLI invocations - bun install, bun run, bun test, bun build - or a working Bun.serve()/bun:sqlite/Bun.file()-based implementation in place of the Node.js equivalent.
Integrations
Built on Bun's own toolchain: its package manager, bundler, test runner, Bun.file/Bun.write/Bun.serve/bun:sqlite/Bun.password built-in APIs, and compatible with most existing Node.js APIs (fs, path, crypto) and package ecosystem via bun install.
Who it's for
JavaScript/TypeScript developers starting a new project with Bun or migrating an existing Node.js project to it for faster installs, execution, testing, and bundling.
const server = Bun.serve({
port: 3000,
fetch(request) {
const url = new URL(request.url);
if (url.pathname === "/") {
return new Response("Hello World!");
}
if (url.pathname === "/api/users") {
return Response.json([
{ id: 1, name: "Alice" },
{ id: 2, name: "Bob" },
]);
}
return new Response("Not Found", { status: 404 });
},
error(error) {
return new Response(`Error: ${error.message}`, { status: 500 });
},
});
console.log(`Server running at http://localhost:${server.port}`);
FAQ
Common questions
Discussion
Questions & comments · 0
Sign In Sign in to leave a comment.