Production Node apps need structured logs and reproducible debugging—not scattered console.log. Learn levels, correlation IDs, and the built-in debugger.
Logging levels
- error — failures requiring attention
- warn — degraded but running
- info — request milestones, startup
- debug — verbose dev-only detail
Structured JSON logs
logger.info({ reqId, method, url, ms }, 'request completed');
Tools like Datadog, CloudWatch, and Loki parse JSON fields for search and alerts.
Debugging
node --inspect— Chrome DevTools debugger- VS Code launch.json — breakpoints in handlers
- Reproduce with fixed NODE_ENV and env vars
Important interview questions and answers
- Q: console.log in production?
A: Acceptable for small apps; structured loggers (pino) add levels, redaction, and performance. - Q: Correlation ID?
A: Unique per request propagated through logs—trace one user action across microservices.
Self-check
- Why log as JSON in production?
- What flag enables Node inspector?