01 Run it here
These files are written to /app on a real filesystem (navigator.storage, not localStorage),
then mounted and executed by the kernel in this tab. require('./lib/greet') resolves the way it does in Node.
This editor executes code in your own tab. It is a demonstration, not a security boundary — do not paste programs you would not run yourself.
02 The layers
Node is a JavaScript API layer sitting on a native one. This keeps that split and replaces the native half with a binding object: read, write, list, stat, mkdir, remove, rename. Seven methods, and the rest is portable.
| file | what it is | Node's equivalent |
|---|---|---|
| lib/path.js | posix resolution bound to the kernel's cwd | path |
| lib/events.js | EventEmitter, including the unhandled-error throw | events |
| lib/buffer.js | Uint8Array with utf8, hex, base64 and latin1 | buffer |
| lib/timers.js | nextTick and the timer entry points | process.nextTick, timers |
| lib/streams.js | Readable, Writable, Transform, for await, pipe | stream |
| lib/fs.js | encodings, errno codes, streams over the binding | fs/promises |
| lib/process.js | argv, env, cwd, exit codes, stdout and stderr | process |
| lib/module.js | CommonJS resolution, cache and evaluation | module, require |
| lib/http.js | servers and a client over a port registry | http, minus the socket |
| hosts/node.js | the binding for a real filesystem | libuv + fs bindings |
| hosts/browser.js | the binding for OPFS, with an in-memory fallback | — |
03 Modules: resolve async, evaluate sync
Node resolves and evaluates a module in one blocking call. A browser cannot block, so the loader
runs in two phases: mount walks the graph and reads every file asynchronously,
then evaluate runs the factories in dependency order with a synchronous
require that only ever reads what mount already found.
App code keeps Node's shape — require('./x') returns exports immediately — because by
the time it runs, everything it can reach is already in memory. Cycles see partial exports instead
of looping, because a module is marked loaded before its body runs.
// what a module body actually runs inside new Function('exports', 'require', 'module', '__filename', '__dirname', 'kernel', 'console', source) // bindings probed in order, like Node ./lib/greet → ./lib/greet.js → ./lib/greet/index.js // bare specifiers walk up for node_modules, honouring package.json main 'tiny' → /app/node_modules/tiny → main: "lib/entry.js"
04 What is deliberately missing
readFileSync does not exist
There is no blocking file syscall in a tab and no second thread to fake one on, so the sync API is absent rather than emulated badly.
listen() takes a port, not a socket
The port is an entry in a registry and http.fetch dispatches into the handler. Same request and response objects; the transport is what is missing.
and no child_process
Both need to start a process or load machine code. Neither has any meaning inside a page, so neither is pretended.
nextTick is a microtask
libuv drains nextTick before promise continuations. A page has no such hook, so ticks are queued ahead of the work that scheduled them — not ahead of every promise.
05 Two hosts, one program
Both bindings are in the repository. The page you are reading uses the browser one; the same kernel
under the Node binding is what node test/kernel.test.mjs exercises — 44 checks covering
path, buffer, events, timer ordering, fs and errno codes, streaming, node_modules resolution,
cycles, the port registry and ECONNREFUSED.
real filesystem
Kernel paths are rooted inside a directory you choose, so a kernel cannot reach outside it. This is how the tests run.
OPFS, or memory
Origin-private storage with real directories and files that survive a reload. Where OPFS is unavailable the same contract is served from a Map.
The next host is the one this architecture was built for: a service worker answering fetch
events, so the same createServer handler serves real URLs from the visitor's own browser.