Test, build, and ship

Compile and ship the application

Compile the Bun application into one executable and review configuration, data, platform, and recovery before release.

10 minute lesson

~~~

Bun can combine your application and the Bun runtime into one executable.

Compile the notes API:

bun build \
  --compile \
  --outfile=notes-api \
  index.ts

Run it without the bun command:

./notes-api

The executable includes the runtime and bundled source. The target machine does not need a separate Bun installation.

Build for the target platform

An executable is platform-specific. A macOS ARM64 binary does not run as a Linux x64 binary.

The safest path is to build in the same operating system and architecture used for deployment. Bun also supports explicit cross-compilation targets when you need them.

Do not embed production secrets into the executable. Supply configuration through protected environment variables at runtime.

Keep notes.sqlite on durable storage. Replacing the executable during a deployment must not replace the database.

Review the release

Before shipping, run:

bun run typecheck
bun test
bun build --compile --outfile=notes-api index.ts

Then verify:

  • the executable starts with production configuration
  • /health returns 200
  • the notes database is writable and backed up
  • logs do not contain secrets or complete request bodies
  • the previous executable is available for rollback

My advice is to keep the first deployment boring. Use one known Bun version, one tested artifact, explicit configuration, and a recovery path.

You now have the complete Bun workflow: run TypeScript, manage packages, use Bun APIs, build an HTTP service, persist data, test it, and ship it.

Lesson completed

Take this course offline

Get every free book and course as PDF and EPUB files.

Get the download library →