Picking up from our conversation about /usr/local/bin. How does Bun work? I hear it's a runtime and a bundler at the same time. What does Bun's executable look like? Is there a binary for the bundler and one for the runtime somewhere in its files?
And then how does that compare to Node, the classic one?
Two ideas of what a should be. Installing Node gives you separate programs: node to run code, npm to install packages, and a bundler, Webpack or Vite, and a test runner, Jest, are more installs again. One tool, one job; you assemble the set. Bun puts all of it in one file, ~/.bun/bin/bun: bun run, bun install, bun build and bun test are the same file told different things. There's no bundler binary to find.
Three names on PATH. node is 190 MB here; npm and npx are scripts it runs. The bundler is yours to install.
Underneath, Node is V8, Google's engine, wrapped in C++; Bun is JavaScriptCore, Apple's, wrapped in Zig. Node lets you swap any piece and has fifteen years behind it; Bun is less to set up and quick, and you trust one team with everything. Both run the same npm packages.
Ah, damn! So npm is a different tool from Node. I never thought about it that way! So pnpm is a different tool too?
Yes. npm is a separate program that ships with Node, the way Safari ships with macOS: it comes with it and it isn't it. node, npm and npx are three files that land in the same folder. pnpm and Yarn do npm's job differently and install separately; pnpm stores each version of a package once on the disk and links projects to it. None of them is Node; they all need Node to run. Bun is the odd one out, replacing all of them with one file.
And then how would you describe what the JavaScript engine is? Is this bit important? I'm just building a mental model here.
It's the most basic piece. The processor only understands ; it has no idea what const x = 5 means. The turns JavaScript into what the processor can run. Everything else, Node, Bun, a browser, is a wrapper that adds what the engine can't do. In Chrome it isn't Chrome running your code, it's V8. In 2009 Ryan Dahl took V8 out of Chrome and gave it files and the network instead of a page: that's Node.
- Chrome is V8 and browser things: the page, tabs, developer tools.
- Node is V8 and server things: files, network, the operating system.
- Bun is JavaScriptCore and server things.
Aahh!! So when you say Node is built in C++, you mean the engine? And the same goes for Bun?
Both parts. V8 is C++, and so is the layer Node built round it. JavaScriptCore is C++ too, Apple's, but Bun's layer round it, files, packages, bundling, is Zig. Engine and runtime are two programs glued together, each written in whatever its makers chose: the gearbox and the rest of the car.
So how is my Brave browser using JavaScriptCore?
It isn't: Brave uses V8. Brave is built on Chromium, the open source base of Chrome, as Edge is; Firefox has SpiderMonkey; only Safari uses JavaScriptCore. That's why Chrome extensions work in Brave. Bun chose JavaScriptCore because it starts faster than V8, which counts for a tool started and stopped all day.
Wait! What is Chromium? And what is it compared to the engine?
Different layers. V8 only runs JavaScript; it doesn't draw a page, fetch one or know there's a mouse. Chromium is the whole open source browser: V8, Blink to turn HTML and CSS into pixels, the network stack, the sandbox that keeps sites apart, the tabs and the address bar. Chrome is Chromium with Google's accounts and sync; Brave and Edge add their own. The engine is under the bonnet, Chromium is the car, and the browsers are dealers' versions of it.
- Added on top
- Shields, ad blocking
- Built from
- Chromium
- Runs JavaScript
- V8, Node's engine too
Vercel and Cloudflare.
Two hosts, built differently. Vercel, the company behind Next.js, runs your code on its servers, on Node, deployed when you push. Cloudflare runs it in hundreds of places at once, close to whoever asked: the edge. Cloudflare Workers don't use Node; that answer said they run on V8 directly, with nothing round it, closer to the metal.
Just out of curiosity, can you trace every folder from /? Include /usr/local/bin, /bin and so on. I want a general understanding of the folder structure on my Mac. You can also briefly mention what some of the folders are for.
/binand/sbin: the essential commands and the shells; tools for running the system itself, such asmount./etc: settings for the whole machine, such ashosts,shellsandpaths./dev: devices shown as files, the disk, and/dev/null, where output goes to vanish./tmp: scratch files, cleared on restart./var: things that change, such as logs. On a Mac all three are links into/private./usr/bin,/usr/lib,/usr/local: the standard tools, their libraries, and what you installed./opt/homebrew: Homebrew, on Apple's chips./Libraryand/System: settings and support files for every user, and Apple's own, read only./Applications,/Volumes, and/Users, a home for each person, yours written~.
Going from /bin towards ~, each step is less the system's and more yours.
So, building our knowledge further: Docker? Docker builds? What is Docker, what problem does it solve, how does it work…
The problem. Your Node is in /usr/local/bin, at one version, leaning on libraries in /usr/lib. A colleague has another version; the server another. Same code, different folders: "works on my machine". Docker ships the folders. A is a program given its own view of the file system, and that view, the , has its own /bin, its own /usr/local/bin/node, your code and its packages. Whatever the host has, the program inside sees only the image.
A Dockerfile is the recipe, built top to bottom: FROM node:20 starts from an image that already has Node, then COPY your code in, RUN npm install, and CMD says what to start. The image is the baked cake; a container is a slice served, and one image can serve any number. Steps are cached as , so the order matters: what changes least goes first. Containers share the host's kernel, so they start in seconds, where a brings a whole system.
Built once: every step ran, and each layer is in the cache now. The dashed line is where app.js goes in.