latencyjs v1.0.1
š LatencyJS - Track API Performance & Identify Slow Requests
ā” Introduction
latencyjs
is a lightweight middleware for Express.js that tracks API response times and logs slow requests using Winston. It helps in identifying performance bottlenecks in your application.
šÆ Features
ā
Track API Response Times
ā
Customizable Threshold (in milliseconds)
ā
Logs Slow Requests with Warning Highlight
ā
Lightweight & Easy to Use
ā
Works Seamlessly with Express.js
š¦ Installation
npm install latencyjs
š Usage Basic Setup Add latencyjs middleware to your Express app:
const express = require("express");
const latency = require("latencyjs");
const app = express();
const PORT = 3000;
// Use latencyjs middleware with a threshold of 200ms
app.use(latency(500));
app.get("/", (req, res) => {
setTimeout(() => res.send("Hello, World!"), 550); // Simulating a slow response
});
app.listen(PORT, () => console.log(`š Server running on port ${PORT}`));
Custom Threshold You can customize the threshold (default: 100ms):
app.use(latency(500)); // Logs requests taking longer than 500ms
š Example Log Output
Slow Request found => GET:/ took: 550.08 milliseconds
š„ Why Use LatencyJS? Performance Monitoring: Quickly identify slow endpoints Customizable Logging: Easily adjust the threshold Zero Configuration Required: Just plug and play š Contributing We welcome contributions! Feel free to submit issues or PRs.
Buy Me a Coffee
Your support means a lot! If you'd like to show your appreciation, you can buy me a coffee ā by visiting the link below
Every contribution helps keep the project alive and encourages further improvements.
š License This project is MIT Licensed.