Socket
Book a DemoInstallSign in
Socket

@imax.i7/express-timeout

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@imax.i7/express-timeout

A express middleware for handling spam requests.

latest
Source
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

Express Timeout

GitHub license

express-timeout is a middleware for Express.js that adds timeout functionality to your routes. With this middleware, you can easily set a timeout for specific routes, ensuring that requests that take too long are automatically terminated.

Installation

npm install @imax.i7/express-timeout

Usage

const express = require("express");
const { RateLimitMiddleware } = require("@imax.i7/express-timeout");

const app = express();

app.use((req, res, next) =>
  RateLimitMiddleware({
    content: {
      error: "The user is now on a timeout.",
      req,
      res,
      next,
    },
  })
);

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

Options

You can customize the timeout duration and handle the timeout event.

// Customize timeout duration (10 seconds) and handle timeout event
app.use((req, res, next) =>
  RateLimitMiddleware({
    req,
    res,
    next,
    onTimeout: handleTimeout,
  })
);

function handleTimeout(req, res) {
  res.status(503).send("Request timed out");
}

Important Note

Make sure to place the @imax.i7/express-timeout middleware before your route handlers to ensure it takes effect.

Contributing

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

License

ISC

Keywords

express

FAQs

Package last updated on 11 Nov 2023

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