Skip to content
WANCODE
BM

Understanding Terminal Commands

16 minIntermediateHTML · CSS · JS

In this lesson

  • Explain what common commands read, write and change
  • Read npm error output and trace it back to package.json
  • Recognise destructive commands before you (or an agent) run them

The big idea

A terminal command is code that runs with your permissions on your files. Treat every suggested command like a code change: know what it reads, what it writes, and whether it can be undone.

Assistants suggest terminal commands constantly, and agent tools can run them for you after you approve. Approving a command you don't understand is like merging code you haven't read. Here's what the everyday ones actually do.

npm install
Reads package.json (and package-lock.json), downloads the listed packages into node_modules, and may update the lockfile. Packages can run their own install scripts, so npm install some-name means trusting that package — check it exists and is spelled right; assistants can suggest package names that don't exist.
npm run dev
Runs whatever command is under "dev" in the scripts of package.json. Usually it starts a development server that keeps running until you press Ctrl+C. Nothing magic: open package.json to see what it runs.
git status
Read-only. Shows your branch, which files are changed, staged or untracked. Safe to run any time — run it before and after an agent edits your project.
rm -rf <path>
Removes files and folders recursively and forcefully: no confirmation, no recycle bin. rm -rf node_modules is common (you can reinstall), but a wrong path — or an empty variable in rm -rf $DIR/ — can delete things you can't get back.
git reset --hard / git push --force
reset --hard throws away uncommitted changes. push --force overwrites the history on the remote, which can erase teammates' work. Neither should be run casually.

Reading error output

Terminal errors look scary because they're long. Read from the top, find the first line that says what went wrong, and ignore the log-file noise at the end. Two npm classics (shortened; exact wording varies between npm versions — older versions print npm ERR!):

Terminal
$ npm run dev
npm error code EJSONPARSE
npm error JSON.parse Failed to parse JSON data.
npm error JSON.parse Note: package.json must be actual JSON, not just JavaScript.

package.json has a syntax error — often a trailing comma or a comment, which JSON doesn't allow.

Terminal
$ npm run dev
npm error Missing script: "dev"
npm error
npm error To see a list of scripts, run:
npm error   npm run

The file is valid, but there's no "dev" entry in scripts. The assistant assumed a script your project doesn't have.

  • command not found — the program isn't installed, or isn't on your PATH (for project tools, run them through npm run or npx).
  • EADDRINUSE — something is already listening on that port; probably your dev server is already running in another terminal.
  • ENOENT — "no such file or directory": a path is wrong, or you're in the wrong folder (check with pwd).

Never paste destructive commands blindly

Before running anything an assistant suggests: can you say what it changes? Can it be undone? Is it touching the path you think? Be extra careful with rm -rf, sudo, git reset --hard, git push --force, git clean, and curl … | sh (which runs a script from the internet without showing it to you). Commit or stash your work before letting an agent run anything big, and don't approve commands in bulk.

There's no real terminal in this lesson. The preview reads package.json the way npm does and shows what npm run … would do — a safe place to practise reading it.

An assistant said: "Run npm run dev to start the Vite dev server." Your terminal printed the EJSONPARSE error above. The preview shows the same problem.

1. Fix the JSON syntax error in package.json (an assistant edited it earlier). 2. Run it again in your head: now npm would say Missing script: "dev". Add a "dev" script that starts Vite's dev server — the command is just vite.

Don't remove the existing scripts or dependencies.

Checks

  • package.json is valid JSON
  • Has a dev script that starts Vite
  • Existing scripts and dependencies are kept

Check understanding

Q1

Which command only reads and never changes your files?

Q2

Where does npm run dev get the command it runs?

Q3

An agent wants to run rm -rf $BUILD_DIR/. What should you check first?

What you learned

  • npm run <name> runs scripts[name] from package.json — read the file to know what runs.
  • Read terminal errors from the top; codes like EJSONPARSE, ENOENT, EADDRINUSE tell you where to look.
  • git status is always safe; rm -rf, reset --hard, push --force, sudo and curl | sh need full attention.
  • Never paste or approve a command you can't explain.
Preview

Console output from your code appears here.

Step 1 of 2