What is nstdlib?

Node.js standard-library modules for any JavaScript runtime.

nstdlib is the Node.js standard library, packaged as plain ES modules that run outside Node. Modules like path, events, stream, url and assert work in browsers, workers, bundlers and other JavaScript runtimes, with the same imports you already know:

import path from "nstdlib/node/path";

path.join("a", "b"); // 'a/b'

It isn't a rewrite. nstdlib is built from Node's own source code, so the modules behave like Node's because they are Node's.

#Who it's for

  • Bundler users. Every nstdlib/node/* module is an ordinary ES module. Your bundler can import it, tree-shake it, and use it in place of a node: import.
  • Workers and edge runtimes. Cloudflare Workers, service workers and other places where Node can't run, but where you still want path.join(), a real URL or an EventEmitter.
  • Browsers. The parts of the standard library that don't need an operating system run in a browser tab. The parts that do throw a clear error instead of failing silently. See Usage.
  • Other JavaScript runtimes. Anything that's neither Node nor a browser.
  • nstd, the standalone runtime from this same project. It combines nstdlib with a host written in Zig to run real Node programs without Node installed.

#How much of Node works?

Modules that are pure JavaScript, like path, events or url, largely behave like the real thing. Modules that need the operating system, like fs or net, need your runtime to provide those features (see Host Integration), and have more gaps.

Support also varies within a module: some exports are verified against real Node, some exist but throw when you call them, and some haven't been tested. The API pages show the measured status of every module.

#nstdlib or nstd?

  • nstdlib (this section) is a package you install from npm and import in your own code.
  • nstd is a single executable that runs .js files without Node installed.

If you want a library to import, you're in the right place. If you want to run a script without installing Node, you want nstd.