Interview Q&A / Node.js

BeginnerQuick answer1 min readUpdated 3 Oct 2026

What are npm scripts and how do you run them?

SHORT ANSWER

Scripts are named shell commands in the scripts field of package.json. Run them with npm run name; start and test also work as npm start and npm test. Local binaries in node_modules/.bin are on the PATH automatically.

Explain it simply

Scripts are shortcuts. Instead of remembering node --watch src/index.js or a long test command, you give it a short name once and everyone on the team runs the same thing.

Example

json
{
  "scripts": {
    "start": "node src/index.js",
    "dev": "node --watch src/index.js",
    "test": "node --test",
    "lint": "eslint .",
    "prebuild": "rm -rf dist",
    "build": "tsc"
  }
}
bash
npm start          # same as npm run start
npm test           # same as npm run test
npm run dev        # custom names need "run"
npm run build -- --pretty   # arguments after -- go to the script

Useful details:

  • npm run with no name lists all scripts.
  • A script named prebuild runs automatically before build, and postbuild after it.
  • Tools installed locally, like eslint, work inside scripts without a global install because npm adds node_modules/.bin to the PATH.

What to say in the interview

"Scripts live in package.json and are run with npm run. start and test have shortcuts, pre and post hooks run around a script, and local binaries are available automatically, so the team does not need global installs."

Common mistakes

  • Typing npm dev instead of npm run dev.
  • Installing tools globally and having the project break on another machine.

#npm#package-json#scripts

Related questions

Practise more Node.js questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open Node.js quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.