Bun foundations

Understand what Bun includes

Meet Bun as a JavaScript runtime, package manager, test runner, and bundler in one executable.

Bun is a toolkit for JavaScript and TypeScript. One bun command gives you several tools that normally come from separate projects.

You get:

  • a runtime for JavaScript and TypeScript
  • a package manager for npm packages
  • a test runner
  • a bundler

With Node.js you assemble this yourself. Node runs the code, npm installs the packages, Jest or Vitest runs the tests, esbuild or webpack bundles. With Bun the same four jobs live in one executable, with one set of docs and one version number.

The runtime fills the same role as Node.js. You give it a program, and Bun runs that program outside the browser.

Bun uses JavaScriptCore, the JavaScript engine behind Safari. Node.js uses V8, the engine behind Chrome. You usually notice the difference through startup speed, compatibility, and the APIs each runtime provides. Bun also runs TypeScript directly, so you don’t need a compile step to get going.

Bun still uses the JavaScript ecosystem

Bun does not ask you to leave npm packages behind. It reads package.json, creates node_modules, and installs packages from the npm registry.

It also implements many Node.js APIs. So a Node.js project can often run with Bun after a small change:

bun run start

But compatibility is not a promise that every project works unchanged. A package may depend on a Node.js API Bun does not fully support. Native add-ons and runtime-specific behavior also need careful testing.

Here is a realistic case. You switch a small Express app to Bun. bun install finishes, bun run start prints the usual “listening” message, and everything looks fine. Then one route fails at the first request, because a dependency relies on a Node.js internal that Bun handles differently. Installation succeeded, startup succeeded, and the app was still broken. The fix is to test the actual request paths, not just the startup.

My advice is simple: treat Bun as its own runtime. Reuse Node.js packages where they work, but test the application with Bun before shipping it.

What we will build

During this course we’ll build a small notes API. It will use TypeScript, Bun.serve(), and SQLite.

We’ll also test it, bundle it, and compile it into a single executable. This gives us a useful path through every important part of Bun, using one project from the first lesson to the last.

Lesson completed