# @moeed/nestjs-rate-limiter

> A Nest.js module for rate limiting using express-rate-limit

Latest version **1.0.0** (published 2023-08-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install @moeed/nestjs-rate-limiter
pnpm add @moeed/nestjs-rate-limiter
yarn add @moeed/nestjs-rate-limiter
bun add @moeed/nestjs-rate-limiter
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2023-08-24 |
| First published | 2023-08-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 101 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Moeed Heidary Goudarzy |
| Maintainers | moeedhy |
| Keywords | nestjs, rate-limiter, api, throttling, middleware, security, express, protection, requests, limiting |

## Links

- npm: https://www.npmjs.com/package/@moeed/nestjs-rate-limiter
- Repository: https://github.com/moeedhy/nestjs-rate-limiter
- Homepage: https://github.com/moeedhy/nestjs-rate-limiter#readme
- Issues: https://github.com/moeedhy/nestjs-rate-limiter/issues
- npm.io page: https://npm.io/package/@moeed/nestjs-rate-limiter

## Dependencies (1)

- [express-rate-limit](https://npm.io/package/express-rate-limit.md) ^6.9.0

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2023-08-24

## README

# Nest.js Rate Limiter Module

A simple and efficient rate limiting module for Nest.js applications. It leverages `express-rate-limit` to protect your application from abuse by limiting the number of requests that a client can make within a defined time window.

## Installation

First, install the module using npm:

```bash
npm install @moeed/nestjs-rate-limiter --save
```

Make sure to also have `express-rate-limit` installed, as it is a peer dependency.

## Usage

Import the `RateLimiterModule` into your root module and configure it using the `register` method:

```typescript
import { RateLimitModule } from '@moeed/nestjs-rate-limiter';

@Module({
  imports: [
    RateLimiterModule.register({
      windowMs: 15 * 60 * 1000, // 15 minutes
      max: 100, // limit each IP to 100 requests per windowMs
    }),
    // ... other modules
  ],
})
export class AppModule {}
```

### Custom Routes

You can specify custom routes to apply rate limiting by using the `routes` option:

```typescript
RateLimiterModule.register({
  windowMs: 15 * 60 * 1000,
  max: 100,
  routes: [
    { path: '/api', method: RequestMethod.ALL },
    { path: '/auth/login', method: RequestMethod.POST },
  ],
})
```

## Options

The following options can be used to configure the rate-limiting behavior:

- `windowMs`: The duration in milliseconds to keep track of requests (default: `60000`).
- `max`: The maximum number of requests allowed within `windowMs` (default: `5`).
- `routes`: An optional array of custom routes to apply rate limiting.

See the [`express-rate-limit` documentation](https://www.npmjs.com/package/express-rate-limit) for more options and details.

## Features

- Easy integration with existing Nest.js applications.
- Extends `express-rate-limit`, allowing for a wide range of customization.
- Global module availability.

## Contributing

Contributions, issues, and feature requests are welcome! Feel free to check [issues page](https://github.com/moeedhy/nestjs-rate-limiter/issues) or open a pull request.

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE.md) file for details.

## Support

If you find this package useful, please consider starring the repository on GitHub or sharing it with your colleagues.

---
_Source: https://npm.io/package/@moeed/nestjs-rate-limiter · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
