This repo is a lightweight set of Bun.js interview questions you can use for preparation or for running interviews.
- What is Bun? A JavaScript runtime (like Node.js/Deno) built on JavaScriptCore (JSC) with a fast toolchain: bundler, test runner, package manager.
- What languages is Bun written in? Mostly Zig, with significant C++ (especially around JavaScriptCore bindings/integration) and some JavaScript/TypeScript in tooling/tests.
- What does Bun ship with? Runtime +
bunpackage manager + bundler/transpiler +bun test. - Where does Bun differ from Node? Different JS engine (JSC vs V8), different compatibility surface, lots of Node APIs are implemented but not always identical in edge cases.
# create a project
bun init
# install deps
bun add <pkg>
# run a file
bun run index.ts
# run tests
bun test-
What is Bun, and what problems does it try to solve?
Bun is a JS runtime + toolchain focused on fast startup, fast installs, and an integrated developer experience (runner, bundler, test runner). -
Which JavaScript engine does Bun use and why does it matter?
Bun uses JavaScriptCore (JSC). Engine choice can impact performance characteristics, available built-ins, and compatibility details compared to Node’s V8. -
Is Bun “drop-in replacement” for Node.js?
Not fully. Bun aims for high Node compatibility, but some Node APIs and edge behaviors may differ; you validate critical workloads and native addons. -
How does Bun handle TypeScript? Do you need a separate build step?
Bun can execute TypeScript directly (transpiling on the fly). For production you may still bundle/build depending on deployment needs. -
When would you avoid Bun in production?
When you rely on Node-only edge behaviors, niche/legacy Node APIs, specific native addons, or you need long-proven runtime stability guarantees.
-
What does
bun installdo differently fromnpm install?
It focuses on speed with an optimized installer and lockfile. It also integrates tightly with Bun’s runtime and tooling. -
What lockfile does Bun use?
Bun usesbun.lockb(binary lockfile) to lock dependency resolution. -
How do you add/remove dependencies?
bun add pkg,bun remove pkg(and-d/--devfor dev deps). -
How would you enforce deterministic installs in CI?
Commit the lockfile and fail CI if it changes; usebun installwith CI-friendly settings and avoid floating versions. -
What are the practical risks of switching package managers on an existing project?
Lockfile churn, subtle resolution differences, postinstall scripts, optionalDependencies behavior, and tooling assumptions.
-
Does Bun support
require()and CommonJS?
Bun supports many CommonJS patterns, but modern projects should prefer ESM when possible; verify any tricky interop modules. -
How do ESM/CJS interop issues show up in Bun?
Default import vs named import differences,__dirname/__filenameexpectations, and packageexportsresolution edge cases. -
Does Bun implement Node’s
fs,path, andhttpmodules?
Many Node built-ins are supported. For interviews, the key is: “mostly compatible, test edge cases.” -
How do you read environment variables in Bun?
process.env.MY_VAR(Node-compatible). Bun also offersBun.envin some contexts; preferprocess.envfor portability. -
How would you debug a Node script that behaves differently on Bun?
Minimize reproduction, check Node API compatibility, confirm ESM/CJS boundaries, and compare engine-specific behavior; add tests.
-
Why is Bun often faster for installs?
It’s implemented with performance as a core goal and uses an optimized dependency installer and lockfile strategy. -
Why can Bun have faster startup times?
Design choices around the runtime, tooling integration, and engine characteristics can reduce overhead versus a multi-tool Node setup. -
What would you measure to justify using Bun?
Install time, cold start, request latency, CPU usage, memory footprint, and CI duration—measured on your workload. -
How would you micro-benchmark fairly across Bun and Node?
Same hardware, pinned versions, warmups, multiple runs, isolate IO, avoid JIT noise, compare p50/p95, and measure RSS/CPU.
-
What is
Bun.file()and when would you use it?
A Bun API for working with files efficiently (often with streaming or easy conversion). Use when you want Bun-native file handling. -
What is
Bun.serve()?
Bun’s built-in HTTP server API for quickly serving requests without extra frameworks. -
How do you handle Web APIs in Bun (Fetch, Request/Response)?
Bun supports many Web-standard APIs likefetch. Prefer Web APIs when you want runtime portability across Bun/Deno/Node (recent Node). -
How do you read JSON quickly in Bun?
Use standardJSON.parseon text; Bun also has optimized paths in some scenarios—main point: profile and don’t guess.
-
How do you run tests?
bun test -
How does
bun testcompare to Jest/Vitest?
It’s built-in and fast. You evaluate ecosystem features you need (reporters, snapshots, mocks, watch mode) and migration cost. -
How would you structure a Bun testing setup in a repo?
Keep tests near code or intests/, ensure deterministic fixtures, avoid environment coupling, and run in CI with pinned Bun version.
-
Does Bun type-check TypeScript at runtime?
Transpiling is not the same as type-checking. For strict type safety you still runtsc --noEmit(or similar) in CI. -
When would you still need a bundler even with Bun?
Browser targeting, tree-shaking requirements, asset pipelines, or when producing a single deployable artifact is needed. -
How do you handle path aliases (like
@/)?
Configuretsconfig.jsonpaths and ensure your runtime/bundler understands them; validate at build time and in tests.
-
How do you pin Bun in CI/production?
Pin a Bun version (e.g., via your CI setup or container base image) to avoid unexpected runtime changes. -
What should you validate before deploying a Node app on Bun?
Integration tests, Node API usage audit, native addon compatibility, performance and memory profiling, and error/observability tooling. -
What’s your rollback strategy?
Keep Node as a fallback runtime, build artifacts compatible with both when possible, and roll out behind a canary/feature flag.
- Walk through migrating a medium Node service to Bun: risk assessment, compatibility testing, and rollout plan.
- Identify and fix an ESM/CJS edge-case bug across runtimes.
- Profile a slow endpoint and decide whether Bun materially helps.
If you want, add more questions by topic or submit improvements to answers (keep them short and practical).