New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

expresseye

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

expresseye

Lightweight Express middleware for logging request performance, response time, and analytics.

latest
Source
npmnpm
Version
1.1.2
Version published
Maintainers
1
Created
Source

expresseye - Express Request Profiler Middleware

🚀 Overview

expresseye is a lightweight Express middleware designed to monitor API request performance, log request details, and send email alerts for slow requests. This helps developers optimize their APIs by identifying slow endpoints and analyzing traffic patterns.

📌 Features

  • Request Logging - Logs API request details (method, response time, response size, etc.).
  • Custom Log Storage - Log to console or files with configurable paths.
  • Rate-Limited Logging - Avoids excessive logging for spammy requests.
  • Latency Alerts via Email - Sends an email when a request takes too long.
  • Selective Monitoring - Choose which routes to monitor/ignore.
  • Performance Optimization - Identify slow endpoints and optimize them.

📚 Why Use expresseye?

  • 🔹 Monitor API Performance - Track slow endpoints & optimize request handling.
  • 🔹 Automated Latency Alerts - Get notified when API response time crosses a set threshold.
  • 🔹 Efficient Logging - Rate-limited logging prevents overwhelming the logs.
  • 🔹 Plug & Play - Simple integration into any Express project.

📝 Installation

npm install expresseye

or

yarn add expresseye

🛠️ Usage (Basic Example)

Import & Use in Express

import dotenv from "dotenv";
import path from "path";
import express, { Request, Response } from "express";
import { requestProfilerMiddleware } from "expresseye";

dotenv.config({ path: path.resolve(__dirname, "../.env") });

const app = express();
const email = process.env.EMAIL_ADDRESS;
const password = process.env.EMAIL_APP_PASSWORD;

app.use(requestProfilerMiddleware({
    logTo: "file",
    filePath: "./logs",
    fileName: "requests.log",
    threshold: 300,
    logLimit: 20,
    logWindowMs: 60000,
    ignoreRoutes: ["/health"],
    sendEmailAlert: false,
    alertEmail: email,
    senderEmail: email,
    senderPassword: password,
    latencyThreshold: 1,
    emailLimit: 3,
    emailWindowMs: 600000,
    routesToMonitor: ["/"]
}));

app.get("/", (req: Request, res: Response) => {
    res.status(200).send("Hello World!");
});

app.get("/health", (req: Request, res: Response) => {
    res.status(200).send("OK");
});

app.listen(3000, () => console.log("Server running on port 3000"));

⚙️ Configuration Options

Below are the configurable arguments with their default values and descriptions:

OptionTypeDefault ValueDescription
logTostring"console""console" or "file" (where to log requests).
filePathstring""Path for log files if logTo is "file".
fileNamestring""File name for log storage.
thresholdnumber500Minimum response time (ms) to log a request.
logLimitnumber10Max logs per IP within logWindowMs.
logWindowMsnumber60000Time window for log limit in ms.
ignoreRoutesstring[][]Routes to exclude from logging.
sendEmailAlertbooleanfalseIf true, sends email alerts for slow requests.
alertEmailstring""Email address to receive alerts.
senderEmailstring""Email address used to send alerts.
senderPasswordstring""App password for sender email.
latencyThresholdnumber1000If request takes more than this (ms), an alert is triggered.
emailLimitnumber5Max emails sent within emailWindowMs.
emailWindowMsnumber600000Time window for email alerts in ms.
routesToMonitorstring[][]Specific routes to monitor for slow responses.

📩 Email Alerts Configuration

  • You can send latency alerts to:
    Your own email (by setting alertEmail to your email).
    Another user’s email (by setting alertEmail to a different email).

🔑 How to Get an Email App Password?

  • You need an app password of your gmail account instead of your normal gmail password.
  • Follow this video guide to generate an app password.

👨‍💻 Environment Variables Setup

Add the following to your .env file:

EMAIL_ADDRESS=your.email@provider.com
EMAIL_APP_PASSWORD=your-generated-app-password

📊 Example Scenarios

ScenarioConfigExpected Behavior
Log all requests to a filelogTo: "file", filePath: "../logs"Requests get logged in ../logs/requests.log.
Send email alerts when response time > 1slatencyThreshold: 1000, sendEmailAlert: trueIf a request takes >1s, an email alert is sent.
Ignore /health routeignoreRoutes: ["/health"]/health requests won't be logged.
Limit logging to 20 requests per IP in 1 minlogLimit: 20, logWindowMs: 60000Prevents spam logging from a single user.

🛠️ Common Issues & Debugging Tips

  • Not receiving email alerts?
    • Check if sendEmailAlert is set to true.
    • Make sure alertEmail and senderEmail are correctly configured.
    • Ensure you’ve set up an email app password correctly.
  • Logs are not being saved in a file?
    • Check if logTo is set to "file".
    • Ensure filePath and fileName are correctly set.

👨‍💻 Author

This project is developed and maintained by Satyam Jha.

🐟 License

This project is licensed under the MIT License and open for contributions!

Keywords

express

FAQs

Package last updated on 06 Apr 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts