How do I debug async code in Node.js?
Check that promises are awaited, errors are caught with try/catch or .catch, and callbacks are called at the right time. Run with --unhandled-rejections=strict to catch missed errors. Async bugs are the most common in Node.js.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in How to Debug Node.js Code Effectively
Use strategic console.log to trace the flow, read error messages carefully since they point at the problem, use the Node.js inspector or VS Code debugger for breakpoints, isolate the bug in a minimal example, and check async code for missing awaits and uncaught errors.
Run node inspect app.js for the built-in debugger, or use VS Code's built-in debugging which lets you set breakpoints in the editor, start debugging, and inspect variables visually. Both are far more powerful than console.log for complex bugs.
Because Node.js error messages are specific. They tell you the file, line, and type of error. Reading the full error instead of jumping to Google often points directly at the problem, saving significant time.
Still have questions?
Browse all our FAQs or reach out to our support team
