Documentation

What is Node?

  • Runtime that executes JavaScript outside the browser (V8 engine).

  • Use it to build CLIs, servers, tools.

  • Examples:

    node -v
    node app.js
    node -e "console.log(process.version, process.arch)"
    

What is npm?

  • The default package manager + public registry for Node projects.

  • Installs dependencies and runs package.json scripts.

    npm init -y
    npm install express
    npm run build
    

What is npx?

  • A package runner (ships with npm) that executes a CLI without installing it globally.

    npx eslint .
    npx --yes create-vite@latest myapp
    # modern equivalent:
    npm exec <command>
    

What is nvm?

  • Node Version Manager: install/switch multiple Node versions per-project or per-shell.

    # load nvm into this shell (if needed)
    export NVM_DIR="$HOME/.nvm"; [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
    
    nvm --version
    nvm ls             # list installed Node versions
    nvm install 20     # install a major/minor
    nvm use 20         # switch current shell
    nvm alias default 20
    

Other tools you may hear about (briefly)

Version managers (like nvm)

  • Volta – toolchain pinning per project (Node + npm + package CLIs), very fast.
  • asdf (with nodejs plugin) – multi-runtime manager (Node, Python, Ruby, etc.).
  • nodenv – Node version manager in the rbenv style.
  • n – simple Node installer/switcher (bash).
  • fnm – “Fast Node Manager” written in Rust.

Alternative runtimes (like Node)

  • Deno – secure JS/TS runtime with web-standard APIs; imports via URLs.
  • Bun – runtime + test runner + package manager; very fast startup.

You don’t need any of these if you’re happy with Node + npm + npx + nvm. They’re just ecosystem options you might encounter.

Node Diagnostics — Quick Guide (macOS, zsh)

A minimal checklist to inspect your Node.js setup. No Homebrew/Yarn/pnpm/Corepack required.


1) Quick snapshot (copy–paste)

echo ">>> Binaries on PATH"; type -a node; type -a npm; type -a npx
echo; echo ">>> Versions"; node -v; npm -v; npx -v
echo; echo ">>> Global npm prefix/root/bin"; npm config get prefix; npm root -g;
echo; echo ">>> Global packages"; npm list -g --depth=0 2>/dev/null | sed -e '1,2d' || true

2) Where Node is coming from (PATH)

type -a node      # every node found on PATH, in order
type -a npm
type -a npx
which -a node     # alternative
echo $PATH        # inspect search order

3) Active runtime details

node -v
npm -v
npx -v
node -p "process.version, process.arch, process.execPath"
node -p "process.versions"   # V8, openssl, etc.

4) If you use nvm (Node Version Manager)

Load nvm in this shell (if it isn’t already):

export NVM_DIR="$HOME/.nvm"; [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"

Inspect:

nvm --version
nvm current
nvm ls                 # Node versions installed via nvm
nvm which node         # path to the active Node binary

Set defaults (optional):

nvm alias default <version>   # e.g., nvm alias default v20.18.3
nvm use <version>             # switch for the current shell

List global npm packages for the active Node:

npm list -g --depth=0

List globals for each installed Node (via nvm):

for v in "$NVM_DIR"/versions/node/*; do
  [ -d "$v" ] || continue
  ver="${v##*/}"
  nvm use "$ver" >/dev/null
  echo "=== $ver ==="
  npm list -g --depth=0 2>/dev/null | sed -e '1,2d' || echo "(no global packages)"
done

5) Project-level checks (run inside a project folder)

node -v && npm -v
cat package.json | head -n 40           # quick peek at name, scripts, engines, etc.
test -f package-lock.json && echo "npm lock present"

6) Optional: detect other version managers (if you use them)

command -v volta  && volta --version    || echo "volta: not found"
command -v nodenv && nodenv --version   || echo "nodenv: not found"
command -v asdf   && asdf --version     || echo "asdf: not found"
command -v n      && n --version        || echo "n: not found"

7) Common gotchas to spot

  • Multiple Node binaries found by type -a node → choose one strategy (e.g., nvm) and ensure its bin is earlier in PATH.

  • Globals aren’t “missing”—they’re per-Node when using nvm. Use the loop above to check each installed version.

  • Build tools for native modules (if needed):

    xcode-select -p  # path to Command Line Tools (should exist)
    

That’s it—run what you need and, if you want, paste the results and I’ll help interpret them.

Contents