Something went wrong. Try again.
Monorepo for the nibling.run platform
Something went wrong. Try again.
# @nibling/kernel
The `nib` prefix on its error codes, worker names, and internals comes from
node-in-browser, the project's original inspiration.
A browser-run Node.js-compatible runtime. JavaScript runs in the browser's own
engine; the parts of Node the browser can't express fall through to a small WASM
residue. **Browser-first is a precedence rule:** for every Node API, use a
browser-native primitive when it can meet Node's behavior (OPFS, WebCrypto,
TextEncoder/Decoder, Web Streams, Workers); compile to WASM only what's left.
Not affiliated with and not derived from StackBlitz WebContainers — the
architecture is our own (see `DESIGN.md`).
## Use it with Vite
```ts
// vite.config.ts
import nib from "@nibling/kernel/vite";
export default defineConfig({ plugins: [nib()] });
```
```ts
import { getKernel } from "@nibling/kernel";
import app from "./examples/express?nib"; // a dir with package.json + installed node_modules
const runtime = await getKernel(); // one per page; survives HMR
const { root } = await runtime.mount(app);
runtime.exec(`${root}/${app.entry}`, { cwd: root });
iframe.src = await runtime.waitForPort(3000);
```
`nib()` sets COOP/COEP on your pages in `vite dev` and `vite preview`, serves the runtime
at `<base>__nib/<version>/` and its Service Worker at `<base>nib-sw.js`, and points the
`@nibling/kernel` import at them, so `getKernel()` needs no options. A `<dir>?nib` import
is a snapshot of that directory, described by its metadata (`{ src, root, entry, kind,
files, bytes }`), never its contents. In dev, edits under it reach the running guest
without a page reload. `vite build` emits the same layout plus a `_headers` for Netlify
and Cloudflare Pages; on another host, `nib({ host: "none" })` prints the headers to set.
`pages: ["/playground/**"]` limits COOP/COEP to the pages that boot the runtime (COOP
breaks OAuth and payment popups). For the `?nib` types, declare the module:
```ts
declare module "*?nib" {
const app: import("@nibling/kernel").NibApp;
export default a…