How to monitor Node.js application health

· Category: Node.js

Short answer

Expose a health check endpoint, collect metrics with libraries like prom-client, and integrate with monitoring tools like Prometheus, Grafana, or Datadog.

Steps

  1. Create a /health route that checks database connectivity and returns 200 or 503.
  2. Instrument your app with prom-client to track request latency, error rates, and event loop lag.
  3. Scrape metrics with Prometheus and build dashboards in Grafana.
  4. Set up alerts for high memory usage, error spikes, and response time degradation.
  5. Use APM tools like New Relic or Elastic APM for distributed tracing.

Tips

  • Health checks should be lightweight and not perform expensive operations.
  • Separate liveness probes (is the app running?) from readiness probes (is it ready to serve traffic?).

Common issues

  • Including dependency health checks that timeout can cause cascading failures in orchestrators.
  • Over-instrumentation adds overhead that degrades performance under load.