api-latency-monitor
v1.0.4
Published
Express middleware for monitoring API latency
Maintainers
Keywords
Readme
API Latency Monitor 🚀
A lightweight and production-ready Express middleware for monitoring API latency, response times, slow endpoints, and backend performance in Node.js applications.
✨ Features
- ⚡ Real-time API latency tracking
- 🚨 Automatic slow API detection
- 🎨 Colored terminal logs
- 📊 Status code monitoring
- 🪶 Lightweight middleware
- 🔧 Configurable slow API threshold
- 📈 Backend performance visibility
- 🛠 Easy Express integration
- 🚀 Zero-config setup
❓ Why API Latency Monitor?
Debugging slow APIs in production is difficult.
Traditional logging systems are often:
- reactive instead of proactive
- difficult to analyze
- missing latency visibility
- hard to monitor in real time
api-latency-monitor solves this by providing:
- instant API response tracking
- real-time slow endpoint detection
- lightweight monitoring
- clean terminal visibility
- minimal setup
📦 Installation
npm install api-latency-monitor🚀 Quick Start
Basic Usage
const express = require("express");
const monitor = require("api-latency-monitor");
const app = express();
app.use(
monitor({
slowThreshold: 1000
})
);
app.get("/", (req, res) => {
setTimeout(() => {
res.send("Fast API");
}, 300);
});
app.get("/slow", (req, res) => {
setTimeout(() => {
res.send("Slow API");
}, 2000);
});
app.listen(3000, () => {
console.log("🚀 Server running on port 3000");
});🖥 Example Output
Fast API
[GET] / -> 200 -> 302msSlow API
⚠️ SLOW API [GET] /slow -> 200 -> 2010ms⚙️ Configuration
| Option | Type | Default | Description | |---|---|---|---| | slowThreshold | number | 1000 | Time in milliseconds after which API is considered slow |
📚 API
monitor(options)
Parameters
{
slowThreshold: number
}Returns
Express middleware function.
🏗 How It Works
The middleware:
- Captures request start time
- Waits for response completion
- Calculates total response time
- Logs latency information
- Detects slow endpoints automatically
📂 Real-World Use Cases
- Detect slow database queries
- Monitor backend performance
- Analyze API bottlenecks
- Debug latency spikes
- Monitor payment APIs
- Improve Express application performance
- Track slow endpoints during development
🛠 Production Ready
Designed for:
- Express.js applications
- Node.js APIs
- internal services
- microservices
- staging environments
- production deployments
Lightweight architecture ensures minimal runtime overhead.
📈 Future Roadmap
- [ ] Average response time tracking
- [ ] Request analytics dashboard
- [ ] Error monitoring
- [ ] File logging support
- [ ] Live terminal dashboard
- [ ] WebSocket monitoring
- [ ] Grafana integration
- [ ] Request history tracking
- [ ] Memory usage analytics
📊 Example Monitoring Scenario
Suppose your application has multiple APIs:
/users
/login
/products
/orders
/paymentsThe middleware automatically tracks latency for every endpoint and highlights slow APIs instantly.
Example:
[GET] /users -> 200 -> 120ms
[POST] /login -> 200 -> 95ms
⚠️ SLOW API [GET] /payments -> 200 -> 2200ms💡 Why Use This Package?
If you want:
- quick API visibility
- lightweight monitoring
- instant latency tracking
- backend debugging
- slow API detection
without using expensive monitoring tools, this package provides a simple and effective solution.
🤝 Contributing
Contributions are welcome!
Feel free to:
- open issues
- suggest new features
- submit pull requests
📄 License
MIT © Harsh Rana
👨💻 Author
Harsh Rana
- GitHub: https://github.com/HarshRana446
- LinkedIn: https://www.linkedin.com/in/harsh-rana-739878302
⭐ Support
If you found this package useful, consider starring the GitHub repository 🚀
