Setup#

Node.js is the operator’s JavaScript runtime outside the browser. Most setup work is picking a Node version, isolating it from system Node, and choosing a package manager (npm, pnpm, yarn, or bun).

Install#

1. Pick a version manager.

  • nvm, the classic shell-based Node version manager.

  • fnm, Rust-based, faster shell integration.

  • volta, project-pinned Node and tools.

  • mise, multi-language version manager (also handles Python, Go, Rust).

$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
$ nvm install --lts
$ nvm use --lts

2. Pick a package manager.

  • npm ships with Node. Default for compatibility.

  • pnpm is faster and disk-efficient (content-addressed store). The default for new work.

  • yarn is the original Facebook alternative; still common.

  • bun is the all-in-one Node-compatible runtime + installer + bundler + test runner.

$ corepack enable
$ corepack prepare pnpm@latest --activate

3. Verify.

$ node --version
$ pnpm --version

Setup project#

1. Bootstrap.

$ mkdir my-tool && cd my-tool
$ pnpm init                        # writes package.json
$ git init && echo node_modules/ > .gitignore

2. Add dependencies.

$ pnpm add cheerio undici
$ pnpm add -D typescript eslint prettier vitest

3. Lay out the source.

my-tool/
├── package.json
├── pnpm-lock.yaml
├── .nvmrc                       # pin Node version
├── src/
│   ├── index.js
│   └── cli.js
└── test/
    └── index.test.js

4. Run.

$ node src/index.js
$ pnpm test

Common Tasks#

Pin Node version per project.

$ echo "lts/*" > .nvmrc
$ nvm use

Run a script defined in package.json.

$ pnpm run build
$ pnpm dlx ts-node script.ts        # ephemeral, no install

Update all dependencies (interactive).

$ pnpm update --interactive --latest

Audit installed packages.

$ pnpm audit
$ npx better-npm-audit audit

References#