MyInternships.in

Node.js Basics

Node.js Debugging

Node has a built-in inspector that connects to Chrome DevTools or VS Code, giving breakpoints, step-through execution and variable inspection — far more effective than scattering console.log calls.


What is Debugging in Node.js?

Node has a built-in inspector that connects to Chrome DevTools or VS Code, giving breakpoints, step-through execution and variable inspection — far more effective than scattering console.log calls.

Debugging example

Start with the inspector
Terminal
node --inspect src/index.js         # attach a debugger
node --inspect-brk src/index.js     # pause on the first line
# then open chrome://inspect in Chrome

Key points to remember

  • VS Code can launch and attach with a one-click debug configuration.
  • console.table and console.dir with { depth: null } beat plain logging for objects.
  • The NODE_DEBUG environment variable enables Node’s internal logging.
  • node --test --watch reruns tests on save.

Common mistakes with Debugging

  • Exposing the inspector port on a public server — it allows arbitrary code execution.
  • Leaving console.log calls in production code instead of using a real logger.

Node.js Debugging— Interview Questions & FAQs

How do I debug Node.js in VS Code?+

Create a launch configuration of type "node" pointing at your entry file, or use the JavaScript Debug Terminal — any node command run there is debuggable with breakpoints automatically.

Related Node.js Topics

Keep learning with these closely related lessons.

Ready to use your Node.js skills?

Find verified Node.js internships and fresher developer jobs across India.

Browse Node.js Internships