Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@aftership/rate-limiter

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

@aftership/rate-limiter

Rate limit for Node.js, with ioredis client

  • 3.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
100
increased by17.65%
Maintainers
1
Weekly downloads
 
Created
Source

rate-limiter

Build Status codecov.io

node npm npm

Rate limit for Node.js, with ioredis client

Installation

npm install @aftership/rate-limiter

Dependency

The client must be an instance of ioredis library.

Examples

const Limiter = require('@aftership/rate-limiter');
const Redis = require('ioredis');

const redisClient = new Redis({
	port: 6379,
	host: '127.0.0.1',
	db: 0
});

redisClient.on('connect', (err) => {
	if (err) {
		console.log(err);
		return;
	}

	// limit to 2 request per every 10s
	const limiter = new Limiter({
		redisClient,
		key: 'the-user-api-key',
		limit: 2, // default is 10
		duration: 10 // default is 60s
	});

	limiter
		.get()
		.then((result) => {
			console.log(result);

			if (result.remaining >= 0) {
				console.log('I can do the request!');
			} else {
				console.log(`I run out of limit! Try again after ${result.reset} second.`);
			}
			process.exit(0);
		})
		.catch((e) => {
			console.log(e);
		});
});

Change log

Please refer to release page

License

Copyright (c) 2019 AfterShip

Licensed under the MIT license.

Keywords

FAQs

Package last updated on 29 Jul 2020

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc