Installation
Install nstdlib and import its modules in your project.
#Install the package
Install nstdlib with your package
manager:
npm install nstdlibpnpm add nstdlibYou can browse the published files on unpkg.
#Import a module
You don't import nstdlib itself. Instead, you import one module at a time,
using the same name Node gives it, prefixed with nstdlib/node/:
import fs from "nstdlib/node/fs";
import { readFile } from "nstdlib/node/fs/promises";| In Node | With nstdlib |
|---|---|
node:fs | nstdlib/node/fs |
node:fs/promises | nstdlib/node/fs/promises |
node:path | nstdlib/node/path |
Besides the nstdlib/node/* modules, the package has three entries of its
own, which have no Node equivalent:
| Import | What it is |
|---|---|
nstdlib/globals | Functions that set up process, Buffer, a filesystem, a network and more. See Host Integration. |
nstdlib/esm | An ES module compiler for runtimes that don't have one. See Host Integration. |
nstdlib/embed | Run whole Node programs: a filesystem, an engine and processes on it. See Usage. |
#What you can import
Only the modules the package publishes can be imported. nstdlib/node/fs
works because fs is published. Other files inside the package can't be
imported, even though they're on disk, and neither can the shared chunks in
node/_chunks/, which are an internal detail of how the package is built.
The published modules are every public node: builtin, plus a few lower-level
modules that the Host Integration page uses. The full list is generated
from the actual build: see the API pages, where each
module's page shows its import path and what works through it.