Skip to content

harshitclub/node-api-observability

Repository files navigation

Node API Observability

A production-style backend observability and monitoring project built with Node.js, Express, TypeScript, Prometheus, Grafana, Loki, and Docker.

This project demonstrates structured logging, metrics collection, centralized error handling, request tracing, and monitoring practices commonly used in real-world backend systems.


Features

  • Express.js API with TypeScript
  • Structured logging with Winston
  • HTTP request logging with Morgan
  • Metrics collection using Prometheus
  • Grafana dashboards for visualization
  • Loki + Promtail log aggregation
  • Request ID tracing
  • Centralized error handling
  • Dockerized development environment
  • Production-style backend architecture

Tech Stack

  • Node.js
  • Express.js
  • TypeScript
  • Docker
  • Prometheus
  • Grafana
  • Loki
  • Promtail
  • Winston
  • Morgan

Project Structure

src/
├── configs/
├── controllers/
├── middlewares/
├── routes/
├── utils/
├── constants/
├── types/
└── index.ts

Getting Started

Clone Repository

git clone https://github.com/harshitclub/node-api-observability.git
cd node-api-observability

Install Dependencies

npm install

Setup Environment Variables

Create a .env file:

PORT=5000
LOG_LEVEL=info
NODE_ENV=development

Run Locally

npm run dev

Run With Docker

docker compose up --build

Services

Service URL
API http://localhost:5000
Prometheus http://localhost:9090
Grafana http://localhost:3000

Metrics

Prometheus metrics endpoint:

/api/metrics

Tracked metrics include:

  • Total HTTP requests
  • Request duration
  • Status codes
  • Node.js system metrics

Logging

Application logs include:

  • HTTP requests
  • Errors
  • Request tracing
  • Response times

Logs are stored inside:

logs/

Observability Stack

Prometheus

Collects application and system metrics.

Grafana

Visualizes metrics through dashboards.

Loki

Stores and aggregates logs.

Promtail

Ships logs from the application to Loki.


Example Use Cases

  • API monitoring
  • Performance analysis
  • Error tracking
  • Backend observability learning
  • Production backend practices

Future Improvements

  • Grafana dashboard provisioning
  • OpenTelemetry integration
  • Redis-based rate limiting
  • Distributed tracing
  • CI/CD pipeline

License

MIT

About

Production-style backend observability and monitoring system built with Node.js, Express, TypeScript, Prometheus, Grafana, Loki, and Docker.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors