express-rate-limit vs limiter vs ratelimiter
Web開発におけるレート制限ライブラリ
express-rate-limitlimiterratelimiter類似パッケージ:

Web開発におけるレート制限ライブラリ

レート制限ライブラリは、特定の時間内に許可されるリクエストの数を制限するために使用されます。これにより、サーバーへの過剰な負荷を防ぎ、サービスの安定性とセキュリティを向上させます。これらのライブラリは、APIの利用制限やボットからの攻撃を防ぐために特に重要です。

npmのダウンロードトレンド

3 年

GitHub Starsランキング

統計詳細

パッケージ
ダウンロード数
Stars
サイズ
Issues
公開日時
ライセンス
express-rate-limit03,237142 kB91日前MIT
limiter01,557158 kB151年前MIT
ratelimiter0725-116年前MIT

機能比較: express-rate-limit vs limiter vs ratelimiter

設定の容易さ

  • express-rate-limit:

    Express-rate-limitは、Expressフレームワークに特化しており、ミドルウェアとして簡単に組み込むことができます。設定もシンプルで、数行のコードで導入可能です。

  • limiter:

    Limiterは、設定がやや複雑ですが、柔軟性が高く、さまざまなストレージオプションをサポートしています。特に、Redisを使用する場合は、強力な機能を提供します。

  • ratelimiter:

    Ratelimiterは、シンプルなAPIを提供しており、迅速に導入できます。設定は簡単で、特定の要件に応じてカスタマイズが可能です。

パフォーマンス

  • express-rate-limit:

    Express-rate-limitは、軽量で効率的な実装を提供し、特に小規模なアプリケーションにおいて優れたパフォーマンスを発揮します。

  • limiter:

    Limiterは、分散環境での使用を考慮して設計されており、パフォーマンスを最適化するためのさまざまなオプションを提供します。

  • ratelimiter:

    Ratelimiterは、シンプルな設計により、オーバーヘッドが少なく、高速なレスポンスを実現します。

拡張性

  • express-rate-limit:

    Express-rate-limitは、基本的な機能を提供しますが、カスタムストレージや他のミドルウェアとの統合が難しい場合があります。

  • limiter:

    Limiterは、さまざまなストレージオプションやカスタマイズ機能を提供しており、特に大規模なアプリケーションにおいて拡張性が高いです。

  • ratelimiter:

    Ratelimiterは、シンプルさを重視しているため、拡張性は限られていますが、特定のニーズに応じたカスタマイズは可能です。

ドキュメントとサポート

  • express-rate-limit:

    Express-rate-limitは、豊富なドキュメントが提供されており、導入やトラブルシューティングが容易です。コミュニティも活発です。

  • limiter:

    Limiterは、ドキュメントが充実しており、特に高度な設定やカスタマイズに関する情報が豊富です。

  • ratelimiter:

    Ratelimiterは、シンプルなライブラリであるため、ドキュメントは簡潔ですが、基本的な使用法については十分な情報が提供されています。

ユースケース

  • express-rate-limit:

    APIエンドポイントのリクエスト制限に最適で、特にExpressアプリケーションにおいて効果的です。

  • limiter:

    大規模な分散システムや複数のインスタンスでの使用に適しており、柔軟な設定が可能です。

  • ratelimiter:

    シンプルなアプリケーションやプロトタイプに最適で、迅速な導入が求められる場合に適しています。

選び方: express-rate-limit vs limiter vs ratelimiter

  • express-rate-limit:

    Expressアプリケーションで簡単に統合でき、ミドルウェアとして機能するため、Expressを使用している場合はこのパッケージを選択してください。特に、簡単な設定で迅速に導入したい場合に適しています。

  • limiter:

    より柔軟な設定やカスタマイズが必要な場合は、Limiterを選択してください。このパッケージは、Redisなどのストレージを使用して、分散環境でのレート制限をサポートします。

  • ratelimiter:

    シンプルで軽量なレート制限が必要な場合は、Ratelimiterを選択してください。特に、特定のシナリオでのパフォーマンスを重視する場合に適しています。

express-rate-limit のREADME

express-rate-limit

tests npm version npm downloads license

Basic rate-limiting middleware for Express. Use to limit repeated requests to public APIs and/or endpoints such as password reset. Plays nice with express-slow-down and ratelimit-header-parser.

Usage

The full documentation is available on-line.

import { rateLimit } from 'express-rate-limit'

const limiter = rateLimit({
	windowMs: 15 * 60 * 1000, // 15 minutes
	limit: 100, // Limit each IP to 100 requests per `window` (here, per 15 minutes).
	standardHeaders: 'draft-8', // draft-6: `RateLimit-*` headers; draft-7 & draft-8: combined `RateLimit` header
	legacyHeaders: false, // Disable the `X-RateLimit-*` headers.
	ipv6Subnet: 56, // Set to 60 or 64 to be less aggressive, or 52 or 48 to be more aggressive
	// store: ... , // Redis, Memcached, etc. See below.
})

// Apply the rate limiting middleware to all requests.
app.use(limiter)

Data Stores

The rate limiter comes with a built-in memory store, and supports a variety of external data stores.

Configuration

All function options may be async. Click the name for additional info and default values.

OptionTypeRemarks
windowMsnumberHow long to remember requests for, in milliseconds.
limitnumber | functionHow many requests to allow.
messagestring | json | functionResponse to return after limit is reached.
statusCodenumberHTTP status code after limit is reached (default is 429).
handlerfunctionFunction to run after limit is reached (overrides message and statusCode settings, if set).
legacyHeadersbooleanEnable the X-Rate-Limit header.
standardHeaders'draft-6' | 'draft-7' | 'draft-8'Enable the Ratelimit header.
identifierstring | functionName associated with the quota policy enforced by this rate limiter.
storeStoreUse a custom store to share hit counts across multiple nodes.
passOnStoreErrorbooleanAllow (true) or block (false, default) traffic if the store becomes unavailable.
keyGeneratorfunctionIdentify users (defaults to IP address).
ipv6Subnetnumber (32-64) | function | falseHow many bits of IPv6 addresses to use in default keyGenerator
requestPropertyNamestringAdd rate limit info to the req object.
skipfunctionReturn true to bypass the limiter for the given request.
skipSuccessfulRequestsbooleanUncount 1xx/2xx/3xx responses.
skipFailedRequestsbooleanUncount 4xx/5xx responses.
requestWasSuccessfulfunctionUsed by skipSuccessfulRequests and skipFailedRequests.
validateboolean | objectEnable or disable built-in validation checks.

Thank You


Thanks to Mintlify for hosting the documentation at express-rate-limit.mintlify.app

Create your docs today


And thank you to everyone who's contributed to this project in any way! 🫶

Issues and Contributing

If you encounter a bug or want to see something added/changed, please go ahead and open an issue! If you need help with something, feel free to start a discussion!

If you wish to contribute to the library, thanks! First, please read the contributing guide. Then you can pick up any issue and fix/implement it!

License

MIT © Nathan Friedly, Vedant K