Skip to content

ruhulaminparvez/express-slowpoke-logger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

express-slowpoke-logger

A lightweight Express.js middleware that tracks API response times and logs slow requests using Winston. It helps identify performance bottlenecks in your application.

🚀 Features

  • Logs all request response times.
  • Highlights slow requests (default: 500ms threshold).
  • Integrates seamlessly with Winston for customizable logging.
  • Lightweight and easy to use.

📦 Installation

Install via npm:

npm install express-slowpoke-logger

🔧 Usage

Integrate the middleware into your Express.js app:

const express = require('express');
const slowpokeLogger = require('express-slowpoke-logger');

const app = express();
const PORT = process.env.PORT || 3000;

// Add the middleware
app.use(slowpokeLogger());

app.get('/', (req, res) => {
  setTimeout(() => {
    res.send('Hello World!');
  }, Math.random() * 1000); // Simulate variable response times
});

app.listen(PORT, () => {
  console.log(`Server running on http://localhost:${PORT}`);
});

⚙️ Configuration

You can customize the slow request threshold and logging level:

app.use(slowpokeLogger({ threshold: 300, level: 'warn' }));
Option Type Default Description
threshold Number 500 Time in milliseconds to log as slow.
level String 'info' Logging level for slow requests.

📜 License

This project is licensed under the MIT License.

✨ Contributing

Contributions are welcome! Please open an issue or submit a pull request.

🛠️ Author

Ruhul Amin Parvez

About

A lightweight Express.js middleware to log slow API responses.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors