Lesson 6.2Lesson 21 of 24
The node command line
Given a scenario and requirements, infer which Node.js CLI command is a good solution.
Key points
- 1node app.js runs a script; arguments after the script name reach the script in process.argv, not Node.js.
- 2node with no script opens the REPL. node -e runs a string of code, and node -p also prints its result.
- 3
--inspectopens a debugger port (9229 by default);--inspect-brkalso pauses before the first line, so you can attach in time. - 4Node.js options go before the script name: node
--require./setup.js app.js preloads a module. - 5Environment variables arrive in process.env as strings.
NODE_ENVis a convention read by your code and libraries, not by Node.js itself.
What the exam guide checks here
Objective wording from the exam guide (English).
- 6.2.K1node CLI: running scripts, the REPL, --inspect for debugging, environment variables
- 6.2.S1Choose the command that runs or debugs a script as required
Lock it in
Answer scenario questions on this topic. Every option comes with an explanation.
Practise 6.2 · 12 questions