Search across all documentation pages
Terminal commands every React, TypeScript, and Node.js developer needs — package management, environment setup, build tooling, and debugging.
Quick-reference recipe card — copy-paste ready.
# Package management
npm install # install all dependencies
npm install zod # add a dependency
npm install -D vitest # add a dev dependency
npm run dev # start dev server
npm run build # production build
# Node version management
nvm install 22 # install Node 22
nvm use 22 # switch to Node 22
node -v # check Node version
# Environment
export PORT=3001 # set env var for this session
cat .env.local # view env file
echo $NODE_ENV # check current environment
# Quick checks
npx tsc --noEmit # type-check without building
npx next lint # run linter
npx vitest run # run tests onceWhen to reach for this: Daily development workflow — installing packages, managing Node versions, running builds, checking types, and debugging issues.
# Setting up a new Next.js project from scratch
npx create-next-app@latest my-app --typescript --tailwind --app --src-dir
cd my-app
npm install zustand zod react-hook-form @hookform/resolvers
npm install -D vitest @testing-library/react
npm run dev
# App running at http://localhost:3000What this demonstrates:
npx runs a package without installing it globallyinstall and install -D for runtime vs dev dependencies# Install
npm install # install from package.json
npm install --legacy-peer-deps # resolve peer dependency conflicts
npm ci # clean install (uses lockfile exactly, faster in CI)
# Add/remove packages
npm install lucide-react # add dependency
npm install -D prettier # add dev dependency
npm uninstall lodash # remove a package
# Install pnpm
npm install -g pnpm
# Equivalent commands
pnpm install # install all
pnpm add zod # add dependency
pnpm add -D vitest # add dev dependency
pnpm remove lodash # remove
pnpm dev # run script (no "run" needed)
pnpm
# Install nvm (macOS/Linux)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash
# Install and use a Node version
nvm install 22
nvm install 20
nvm use 22
nvm alias default 22 # set default for new terminals
# Use version from .nvmrc file
echo "22" > .nvmrc
# Set for current command only
PORT=3001 npm run dev
NODE_ENV=production npm run build
# Set for current session
export DATABASE_URL="postgresql://localhost:5432/mydb"
# View current env vars
env | grep NODE
printenv PORT
# .env file structure (Next.js)
# Type-check without building
npx tsc --noEmit
# Type-check in watch mode
npx tsc --noEmit --watch
# Generate declaration files
npx tsc --declaration --emitDeclarationOnly
# Check tsconfig
npx tsc --showConfig
# Find specific type errors
npx tsc --noEmit 2>&1 | grep
# Next.js production build
npm run build
# Shows route sizes, static vs dynamic, bundle breakdown
# Analyze bundle size
npm install -D @next/bundle-analyzer
ANALYZE=true npm run build
# Check package size before installing
npx package-size zustand zod lodash
# or use https://bundlephobia.com
# Measure build time
# Node.js debugger
node --inspect server.js # attach Chrome DevTools
node --inspect-brk server.js # break on first line
# Debug a Next.js app
NODE_OPTIONS='--inspect' npm run dev
# Memory profiling
node --max-old-space-size=4096 server.js # increase heap to 4GB
node --heap-prof server.js # generate heap profile
# Test an API endpoint
curl http://localhost:3000/api/health
curl -s http://localhost:3000/api/users | jq .
# POST with JSON body
curl -X POST http://localhost:3000/api/users \
-H "Content-Type: application/json" \
-d '{"name": "Alice", "email": "alice@example.com"}'
# POST with auth header
curl -H "Authorization: Bearer $TOKEN
Things that will bite you. Each gotcha includes what goes wrong, why it happens, and the fix.
Port already in use — EADDRINUSE: address already in use :::3000. Fix: lsof -ti :3000 | xargs kill -9 or use a different port: PORT=3001 npm run dev.
Node version mismatch — Build works locally but fails in CI or for teammates. Fix: Add a .nvmrc file and engines field in package.json: "engines": { "node": ">=22" }.
npm install vs npm ci — npm install can update the lockfile, causing unexpected changes. Fix: Use npm ci in CI pipelines — it uses the lockfile exactly and is faster.
Missing NEXT_PUBLIC_ prefix — Client-side code gets undefined for env vars. Fix: Env vars accessed in the browser must start with NEXT_PUBLIC_. Server-only vars don't need the prefix.
Global package conflicts — Global installs of next, typescript, etc. conflict with project versions. Fix: Use npx instead of global installs. Remove globals: npm uninstall -g next.
Heap out of memory — Large builds crash with FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed. Fix: NODE_OPTIONS="--max-old-space-size=8192" npm run build.
Other ways to solve the same problem — and when each is the better choice.
| Alternative | Use When | Don't Use When |
|---|---|---|
pnpm | Faster installs, monorepos, strict dependency resolution | Simple projects where npm is sufficient |
yarn | Existing projects already using yarn | New projects (pnpm or npm are preferred) |
bun | Maximum speed, built-in test runner | Production stability is critical (newer runtime) |
fnm | Faster Node version switching than nvm | Already using nvm and it works fine |
volta | Automatic Node version switching per project | Simple projects with one Node version |
npm install and npm ci?npm install reads package.json and may update package-lock.jsonnpm ci uses the lockfile exactly, deletes node_modules first, and is fasternpm ci in CI pipelines for reproducible buildsnpx instead of installing a package globally?npx for one-off commands like npx create-next-app or npx tsc --noEmitnpx always uses the project-local version if availableecho "22" > .nvmrc
nvm usenvm use reads .nvmrc and switches to that versionnvm alias default 22undefined for an environment variable?NEXT_PUBLIC_DATABASE_URL) are not exposed to the browserlsof -ti :3000 | xargs kill -9PORT=3001 npm run dev.nvmrc file with the Node version (e.g., 22)engines field in package.json: "engines": { "node": ">=22" }npm install -D @next/bundle-analyzer
ANALYZE=true npm run buildnpx depcheck to find unused dependenciesNODE_OPTIONS='--inspect' npm run devchrome://inspect in Chrome and click "inspect" on your Node process--inspect-brk to break on the first lineNODE_OPTIONS="--max-old-space-size=8192" npm run buildnpx tsc --noEmit--noEmit runs the type checker without generating .js files--watch for continuous checking during developmentnpx tsc --noEmit 2>&1 | grep "error TS" | wc -lgrep "error TS" to isolate type errors from other outputpnpm and npm?pnpm uses a content-addressable store, so shared dependencies are not duplicated on diskpnpm has stricter dependency resolution (prevents phantom dependencies)pnpm is faster for installs, especially in monoreposnpm is pre-installed with Node and has broader ecosystem familiarity