open-index/open-npm huggingface dataset:
npm package: @rlimit/storage
Description: A tiny (523b) `rlimit.com` store for `hono-rate-limiter` and `express-rate-limit` middleware.
Latest version: 0.0.8

# rlimit.com rate limiting storage

A distributed rate limiting store for the [`hono-rate-limiter`](https://github.com/rhinobase/hono-rate-limiter) and [`express-rate-limit`](https://github.com/express-rate-limit/express-rate-limit) middleware.

## Prerequisites

Sign up for a free account at [rlimit.com](https://rlimit.com) and create a namespace, or use `example` as namespace ID to test the functionality.

## Installation

From the npm registry:

```sh
# Using npm
> npm install @rlimit/storage
# Using yarn or pnpm
> yarn/pnpm add @rlimit/storage
```

## Usage

### Importing

This library is provided in ESM as well as CJS forms, and works with both
Javascript and Typescript projects.

**This package requires you to use Node 16 or above.**

Import it in a CommonJS project (`type: commonjs` or no `type` field in
`package.json`) as follows:

```ts
const { Store } = require("@rlimit/storage");
```

Import it in a ESM project (`type: module` in `package.json`) as follows:

```ts
import { Store } from "@rlimit/storage";
```

### Examples

To use it with a [`hono-rate-limiter`](https://github.com/rhinobase/hono-rate-limiter) middleware:

Interactive demo on [ratelimit.new/hono-rate-limiter](https://ratelimit.new/hono-rate-limiter)

```ts
import { serve } from "@hono/node-server";
import { Hono } from "hono";
import { Store } from "@rlimit/storage";

import honoRateLimiter from "hono-rate-limiter";

const limiter = honoRateLimiter.rateLimiter({
  windowMs: 60 * 1000, // 1 minute
  limit: 20, // Limit each key (from keyGenerator) to 20 requests per `window` (here, per 1 minute)
  standardHeaders: "draft-6", // draft-6: `RateLimit-*` headers; draft-7: combined `RateLimit` header
  keyGenerator: () => "<unique_key>", // Method to generate custom identifiers for clients, default to IP address
  store: new Store({
    namespace: "example", // your rlimit.com namespace ID
  }),
});

const app = new Hono();

app.use(limiter);

app.get("/", (c) => {
  // your application logic here
  return c.json({ message: "Hello Hono!" });
});

serve(app);
```

To use it with a [`express-rate-limit`](https://github.com/express-rate-limit/express-rate-limit) middleware:

Interactive demo on [rlimit.com/demos/nodejs-express](https://rlimit.com/demos/nodejs-express)

```ts
import express from "express";
import { rateLimit } from "express-rate-limit";
import { Store } from "@rlimit/storage";

const app = express();

let rlimit = rateLimit({
  // limit IP address to 3 requests every 5 seconds
  limit: 3,
  windowMs: 5_000,
  store: new Store({
    namespace: "example", // your rlimit.com namespace ID
  }),
});

app.use(rlimit);
app.get("/", async (req, res) => {
  res.send("Hello World!");
});

app.listen(3000, () => {
  console.log("Express application started");
});
```