Node.js Developer Commands
Terminal commands every React, TypeScript, and Node.js developer needs - package management, environment setup, build tooling, and debugging.
Search across all documentation pages
Terminal commands every React, TypeScript, and Node.js developer needs - package management, environment setup, build tooling, and debugging.
🤖 Read the SystemsArchitect.io Blog for over 100+ cloud architecture articles 🔥
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
# Inspect
npm list --depth=0 # top-level installed packages
npm outdated # check for updates
npm audit # security vulnerabilities
npm audit fix # auto-fix vulnerabilities
# Scripts
npm run dev
npm run build
npm run start
npm test
npm run lint
# View a package before installing
npm info zustand # package details
npm info zustand versions # all published versions
# Link a local package for development
cd ../my-library && npm link
cd ../my-app && npm link my-library# 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 build
# Workspace commands (monorepo)
pnpm -r build # run build in all packages
pnpm --filter @app/web dev # run dev in specific package# 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
nvm use # reads .nvmrc
# List installed versions
nvm ls
# List available versions
nvm ls-remote | grep "Latest LTS"# 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)
# .env - all environments (committed)
# .env.local - local overrides (gitignored)
# .env.development - dev only
# .env.production - prod only
# .env.test - test only
# Access in Next.js
# Server: process.env.DATABASE_URL
# Client: process.env.NEXT_PUBLIC_API_URL (must have NEXT_PUBLIC_ prefix)
# Check what env vars your app sees
node -e "console.log(process.env.NODE_ENV)"# 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 "error TS"
# Count type errors
npx tsc --noEmit 2>&1 | grep "error TS" | wc -l
# Check a specific file
npx tsc --noEmit src/lib/utils.ts# 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
time npm run build
# Check what's in node_modules
du -sh node_modules # total size
du -sh node_modules/* | sort -rh | head -20 # largest packages
npx depcheck # find unused dependencies# 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
# Quick REPL for testing
node
> const { z } = require('zod')
> z.string().email().safeParse('test@example.com')
# Execute a one-liner
node -e "console.log(Date.now())"
node -e "console.log(require('./package.json').version)"
node -p "require('os').cpus().length" # -p prints the result
# Check module resolution
node -e "console.log(require.resolve('react'))"# 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" \
http://localhost:3000/api/protected
# Time a request
curl -o /dev/null -s -w "Total: %{time_total}s\nTTFB: %{time_starttransfer}s\n" \
http://localhost:3000
# Watch a port
lsof -i :3000 # what's using port 3000
kill -9 $(lsof -ti :3000) # kill whatever's on port 3000Things 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 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 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 22NEXT_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 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 familiarityReviewed by Chris St. John·Last updated Jul 10, 2026
🤖 Read the SystemsArchitect.io Blog for over 100+ cloud architecture articles 🔥