Node.js & JS Toolchain¶
Package managers, runners, debugging, and TypeScript workflows.
Package Managers¶
npm¶
Install dependencies:
Add a dev dependency:
Run a script from package.json:
Check for outdated packages:
Update interactively:
pnpm¶
Drop-in npm replacement with faster installs and disk savings:
Install:
brew install pnpm·npm install -g pnpm
Bun¶
All-in-one runtime, bundler, and package manager:
bun install # install deps (reads package.json)
bun run dev # run scripts
bun add hono # add a dependency
Run a file directly (no build step):
Install:
brew install oven-sh/bun/bun·curl -fsSL https://bun.sh/install | bash
npx — Run Without Installing¶
Run a package without installing globally:
Use a specific version:
tsx — Run TypeScript Directly¶
Execute TypeScript without a build step (via Node.js):
Watch mode:
Install:
npm install -g tsx
Debugging¶
Node.js Inspector¶
Start with the debugger:
Break on first line:
Then open chrome://inspect in Chrome to connect.
Environment Variables¶
Inline environment variables:
Load from .env file (Node.js 20.6+):
Vitest / Jest CLI¶
Run tests:
Watch mode:
Run a specific test file:
Run tests matching a pattern:
Show coverage:
Comparison¶
| Feature | npm | pnpm | Bun |
|---|---|---|---|
| Speed | Baseline | ~2x faster | ~5x faster |
| Disk usage | Duplicates deps | Hard links (saves space) | Compact |
| Lockfile | package-lock.json |
pnpm-lock.yaml |
bun.lockb |
| Built-in runner | No | No | Yes (TypeScript, JSX) |
| Compatibility | Universal | High | Growing |