Server Side JavaScript8% of the exam

Node.js CLI commands and flags

Which node command fits the job: --check for a syntax-only pass, -e and -p for inline code, --require and --import to preload modules, --inspect and --inspect-brk for debugging, plus how arguments reach process.argv, how process.env is read and how the REPL works.

Official exam objective
Given a scenario and requirements, infer which Node.js CLI command is a good solution.

~6 min read · 5 practice questions ·

What the exam expects

  • Pick the node flag for a requirement: syntax-check without running, evaluate or print inline code, preload a module, or attach a debugger before the first line runs.
  • Place options and script arguments in the right order and predict the contents of process.argv.
  • Read configuration from environment variables with process.env (and --env-file), knowing values are strings.
  • Start and use the REPL for quick experiments.

Key terms: option (a flag such as --check written before the entry script, read by Node.js); argument (anything after the entry script, passed to the script); inspector (the V8 debugging agent that tools such as Chrome DevTools attach to); preload (a module run at startup before the entry script); REPL (Read-Eval-Print Loop, the interactive node prompt).

Key facts

Synopsis
Detail
node [options] [V8 options] [script.js | -e "script" | - ] [arguments]
process.argv[0], [1]
Detail
process.execPath, then the absolute path of the entry script
-c, --check
Detail
Syntax check without executing
-p, --print
Detail
Identical to -e but prints the result
Preload order
Detail
--require modules run before --import modules
Inspector default
Detail
127.0.0.1:9229
--inspect-brk
Detail
Breaks at the start of the user script
--env-file precedence
Detail
The existing environment wins over the file
process.env values
Detail
Assigned values are converted to strings (deprecated behavior)
REPL _
Detail
Result of the most recently evaluated expression, until _ is assigned explicitly
Sources for this section (5)
  • Why does `node report.js --verbose` leave `--verbose` for the script instead of Node.js?
  • When should you choose `--inspect-brk` over `--inspect`?
  • Which flag preloads a CommonJS module before the entry script?
  • What type is `process.env.PORT` when set to 8080?

The questions are free to read. Answers with their sources and self-grading are included with the pack.

Keep reading with the JavaScript Developer pack

  • Core concepts
  • Exam traps
  • Worked scenario

The pack includes:

  • All 24 lessons of the JavaScript Developer guide, with reading progress
  • Interactive decision walks and step-by-step sequence steppers
  • Inline practice questions and one-click topic practice (5 questions for this lesson)
  • An official source cited for every claim
  • An AI tutor that answers from the guide
  • Unlimited timed practice exams

Practice for the JavaScript Developer exam