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.
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
nodeflag 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
- 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
-ebut prints the result
- Detail
--requiremodules run before--importmodules
- 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)
_- Detail
- Result of the most recently evaluated expression, until
_is assigned explicitly
- Why does
node report.js --verboseleave--verbosefor the script instead of Node.js? - When should you choose
--inspect-brkover--inspect? - Which flag preloads a CommonJS module before the entry script?
- What type is
process.env.PORTwhen 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
- Practice exams purchase adds inline bank questions and topic practice (5 questions for this lesson)
- An official source cited for every claim
- An AI tutor that answers from the guide
- Choose guide-only, practice-only, or save $4 with both