CCA Prep

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.

The node command linenodeoptions before the scriptnamenode app.jsrun a scriptnodeREPL · .help · .exit--inspect ·--inspect-brkdebugger on port 9229-e · -prun or print a snippet-r / --requirepreload a moduleNAME=value nodeapp.jsread in process.env

Key points

  1. 1node app.js runs a script; arguments after the script name reach the script in process.argv, not Node.js.
  2. 2node with no script opens the REPL. node -e runs a string of code, and node -p also prints its result.
  3. 3--inspect opens a debugger port (9229 by default); --inspect-brk also pauses before the first line, so you can attach in time.
  4. 4Node.js options go before the script name: node --require ./setup.js app.js preloads a module.
  5. 5Environment variables arrive in process.env as strings. NODE_ENV is 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