How to use the limiter.RateLimiter function in limiter

To help you get started, we’ve selected a few limiter examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zeke / electron-developers / script / build-profiles.js View on Github external
require('dotenv-safe').load()

const fs = require('fs')
const path = require('path')
const RateLimiter = require('limiter').RateLimiter
const limiter = new RateLimiter(5000, 'hour')
const ghUser = require('gh-user')
const users = require('../usernames.json')

users
// .slice(0,3)
.forEach(user => {
  const username = user.user
  const cachedFile = path.join(__dirname, `../profiles/${username}.json`)

  if (fs.existsSync(cachedFile)) {
    console.log(`${username} (already cached)`)
    return
  }

  limiter.removeTokens(1, () => {
    ghUser(username, process.env.GITHUB_TOKEN).then(profile => {
github Morning-Train / Mail-notifications-for-Trello / app.js View on Github external
var Trello = require("./controller/trello.js");
var nodemailer = require("nodemailer");
var express = require("express");
var app = express();
var bodyParser = require("body-parser");
var mongoose = require('mongoose');

var connectionString = "mongodb://localhost/mailnotifiersForTrello";
mongoose.connect(connectionString);
var db = mongoose.connection;
db.once('open', function () { console.log('MongoDB connection successful.'); });

var http = require("https");

var RateLimiter = require('limiter').RateLimiter;
var limiter = new RateLimiter(50, 10000);

var passport = require('passport');
var LocalStrategy = require('passport-local').Strategy;
var expressSession = require('express-session');

var bcrypt = require('bcrypt');
var SALT_WORK_FACTOR = 10;

// Loading config
var config = require('./config/config');

// Notifier Schema for mails
var NotifierSchema = new mongoose.Schema({
    project: String,
    email: Array,
    board: String,
github CapacitorSet / box-js / integrations / export / export.js View on Github external
if (!argv["cuckoo-address"])
		throw new Error("Please enter a valid Cuckoo address (see --help for more information).");
	cuckooAddress = argv["cuckoo-address"];
	if (!/^http/i.test(cuckooAddress))
		cuckooAddress = "http://" + cuckooAddress;
}

let malwrApiKey;
// Malwr doesn't enforce rate limits, but let's be nice
const malwrRateLimit = 1;
let malwrLimiter;
if (argv["malwr-all-files"] || argv["malwr-executables"]) {
	if (!argv["malwr-key"])
		throw new Error("Please enter a valid API key for Malwr (see --help for more information).");
	malwrApiKey = argv["malwr-key"];
	malwrLimiter = new RateLimiter(malwrApiKey, "second");
}

let vtApiKey;
let vtRateLimit, vtLimiter;
if (argv["vt-urls"] || argv["vt-all-files"] || argv["vt-executables"]) {
	if (!argv["vt-key"])
		throw new Error("Please enter a valid API key for VirusTotal (see --help for more information).");
	vtApiKey = argv["vt-key"];
	// The public API is limited to 4 requests per minute.
	vtRateLimit = argv["vt-rate-limit"] || 4;
	vtLimiter = new RateLimiter(vtRateLimit, "minute");
}

let urls, numUrls;
if (argv["cuckoo-urls"] || argv["vt-urls"]) {
	log("info", "Parsing URLs...");
github olymp / olymp / cms / graphql / server / rate-limit.js View on Github external
if (keys.length !== 2) return;
    var type = fetchType(ast, keys[1]);
    var directive = (0, _get3.default)(type, 'directives', []).find(function (d) {
      return (0, _get3.default)(d, 'name.value') === 'rateLimit';
    });
    var ip = context.ip;

    if (type && directive) {
      var cachedLimiter = cache.get(ip);
      if (cachedLimiter) {
        if (cachedLimiter.getTokensRemaining() <= 0) {
          throw new Error('too many requests from your ip!');
        }
        cachedLimiter.tryRemoveTokens(1);
      } else {
        cachedLimiter = new _limiter.RateLimiter(limit, per);
        cachedLimiter.id = _shortid2.default.generate();
      }
      cachedLimiter.cost = 1;
      cachedLimiter.limit = limit;
      cachedLimiter.remaining = Math.floor(cachedLimiter.getTokensRemaining());
      cachedLimiter.resetAt = cachedLimiter.tokenBucket.interval;
      cachedLimiter.nodeCount = 0;
      context.rateLimit = cachedLimiter;
      cache.set(ip, cachedLimiter, 10000);
    }
  },
  queries: '\n    rateLimit: RateLimit\n  ',
github shoutout-labs / dynamodb-mongodb-migrate / src / MigrationJob.js View on Github external
constructor(sourceTableName, targetTableName, targetDbName,sourceConnectionOptions, targetConnectionOptions, dynamodbEvalLimit, dynamoDbReadThroughput) {
        this.sourceTableName = sourceTableName;
        this.targetTableName = targetTableName;
        this.targetDbName = targetDbName;
        this.mapperFunction = (item) => { return item; };
        this.filterFunction = () => { return true; };
        this.dynamoDBDAO = new DynamoDBDAO(sourceTableName,sourceConnectionOptions.region,sourceConnectionOptions.accessKeyId,sourceConnectionOptions.secretAccessKey);
        this.mongoDBDAO = new MongoDBDAO(this.targetTableName, this.targetDbName,targetConnectionOptions.host, targetConnectionOptions.user, targetConnectionOptions.password);
        this.dynamodbEvalLimit = dynamodbEvalLimit || 100;
        this.filterExpression = null;
        this.expressionAttributeNames = null;
        this.expressionAttributeValues = null;
        this.dynamoDbReadThroughput = dynamoDbReadThroughput ? Number(dynamoDbReadThroughput) : 25;
        this.limiter = new RateLimiter(this.dynamoDbReadThroughput, 1000);
        this._removeTokens = (tokenCount) => {
            return new Promise((resolve, reject) => {
                this.limiter.removeTokens(tokenCount, () => {
                    resolve();
                });
            });
        }
    }
github stevenpack / cryptowarrior / src / events / Throttle.ts View on Github external
constructor(num: number, period?: string) {
        if (period) {
            this.limiter = new RateLimiter(num, period);
        } else {
            this.limiter = new RateLimiter(1, num);
        }

    }
github pevers / images-scraper / lib / yahoo-images-scraper.js View on Github external
Scraper.prototype.list = function (options) {
	var self = this;

	if (!options || !options.keyword) return Promise.reject(new Error('no keyword provided'));

	this.rlimit = new RateLimiter(options.rlimit || 0, 'second');
	this.userAgent = options.userAgent || 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36';

	var base = 'https://images.search.yahoo.com/search/images?fr=yfp-t-404&fr2=piv-web&o=js&p=%&tab=organic&tmpl=&nost=1';

	var roptions = {
		'User-Agent': this.userAgent
	}

	var result = [];
	var nextPage = function (n) {
		return new Promise(function (resolve, reject) {
			roptions.url = base.replace('%', options.keyword) + '&b=' + n;
			self.rlimit.removeTokens(1, function() {
				request(roptions, function(err, response, body) {
					if (!err && response.statusCode === 200) {
						var html = JSON.parse(body).html;
github stevenpack / cryptowarrior / src / events / Throttle.js View on Github external
constructor(num, period) {
        if (period) {
            this.limiter = new RateLimiter(num, period);
        }
        else {
            this.limiter = new RateLimiter(1, num);
        }
    }
    /**

limiter

A generic rate limiter for the web and node.js. Useful for API clients, web crawling, or other tasks that need to be throttled

MIT
Latest version published 4 years ago

Package Health Score

73 / 100
Full package analysis

Popular limiter functions