CRT-600 practice question 11 of 30

A developer needs to debug a Node.js web server because a runtime error keeps occurring at one of the endpoints. The developer wants to test the…

Full set: 223 questions
A developer needs to debug a Node.js web server because a runtime error keeps occurring at one of the endpoints. The developer wants to test the endpoint on a local machine and make the request against a local server to look at the behavior. In the source code, the server, js file will start the server. the developer wants to debug the Node.js server only using the terminal. Which command can the developer use to open the CLI debugger in their current terminal window?
Answer options
A: node -i server.js
B: node inspect server,js Correct answer
C: node server,js inspect
D: node start inspect server,js
Correct Answer:
B. node inspect server,js
Explanation

The node inspect command is the correct way to start the Node.js command-line interface (CLI) debugger. When node inspect server.js is executed, it launches the V8 Inspector, which is Node.js's built-in debugging utility. This command specifically starts the script (server.js) and immediately pauses execution on the first line, providing a debug prompt directly within the same terminal window. This allows the developer to step through the code, inspect variables, and analyze the application's behavior as requested in the scenario.

Why Incorrect

A. node -i server.js: The -i or --interactive flag starts the REPL (Read-Eval-Print Loop) after the script runs, which is for interactive scripting, not for debugging a server process.
C. node server.js inspect: This is incorrect syntax. inspect is an option for the node executable and must precede the script name, not follow it as a script argument.
D. node start inspect server.js: This is invalid syntax. start is not a native command for the node executable; it is typically used with package managers like npm (e.g., npm start).

References

1. Node.js Official Documentation

Debugging Guide: The documentation explicitly states the command to start the CLI debugger. It details that node inspect <script.js> starts the Node.js debugger and breaks on the first line of the script.

Source: Node.js v18.18.0 Documentation

Debugging — Getting Started

Command-line options. Section: "Inspector".

Reference: "Start the Node.js debugger CLI by passing the inspect argument when starting a script: $ node inspect myscript.js"

2. Node.js Official Documentation

Command-line options: This document lists all available command-line flags for the node executable. The inspect keyword is documented as the method to activate the V8 inspector and launch the CLI debugger.

Source: Node.js v18.18.0 Documentation

Command-line options.

Reference: The entry for inspect and --inspect describes their function in activating the debugger. inspect is specifically noted for its integration with the CLI debugger.

Scroll to Top