function checkReqsIntensivity (req, res, next) {
  var user_id = req.user && req.user.id ? req.user.id : 0
  var ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress || req.socket.remoteAddress

  var minute = parseInt(Date.now() / 1000 / (options.TimeFrameInMinutes * 60), 10)
  var requestKey = 'RateLimitter:' + (user_id || ip) + ':' + req.method + ':' + minute

  // next minute
  var resetMinute = minute * (options.TimeFrameInMinutes * 60) + (options.TimeFrameInMinutes * 60)

  function errHandler (err) {
    console.log('RateLimitter Error')
    console.log(err)
    return next()
  }

  function processResponse (info) {
    if (info.too_often) {
      console.log('Please slow down, you request too frequently.')
      return res.sendStatus(429)
    } else {
      // save reqnum into redis
      redis.setex(requestKey, options.TimeFrameInMinutes * 60, ++info.reqnum, function (err) {
        if (err) {
          return errHandler(err)
        }
        return next()
      })
    }
  }

  redis.get(requestKey, function (err, reqnum) {
    if (err) {
      return errHandler(err)
    }

    reqnum = parseInt(reqnum, 10) || 0
    var too_often = false
    var remaining = options.maxUserRequestLimitPerTimeFrame[req.method] - reqnum
    if (remaining < 0) {
      too_often = true
      res.setHeader('X-Rate-Limit-Reset', resetMinute)
    }

    res.setHeader('X-Rate-Limit-Limit', options.maxUserRequestLimitPerTimeFrame[req.method])
    res.setHeader('X-Rate-Limit-Remaining', Math.max(remaining, 0))

    processResponse({too_often: too_often, reqnum: reqnum || 0})
  })
}
/**
 * Checks requests intensivity from single User (if any) OR IP address
 * And skips check in we are in development mode
 * @param req
 * @param res
 * @param next
 * @returns next()
 */
Checks requests intensivity from single User (if any) OR IP address
And skips check in we are in development mode
@param req
@param res
@param next
@returns next()
Checks requests intensivity from single User ( if any ) OR IP address And skips check in we are in development mode @param req @param res @param next @returns next ()
function checkReqsIntensivity (req, res, next) {
  var user_id = req.user && req.user.id ? req.user.id : 0
  var ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress || req.socket.remoteAddress
  var minute = parseInt(Date.now() / 1000 / (options.TimeFrameInMinutes * 60), 10)
  var requestKey = 'RateLimitter:' + (user_id || ip) + ':' + req.method + ':' + minute
  var resetMinute = minute * (options.TimeFrameInMinutes * 60) + (options.TimeFrameInMinutes * 60)
  function errHandler (err) {
    console.log('RateLimitter Error')
    console.log(err)
    return next()
  }
  function processResponse (info) {
    if (info.too_often) {
      console.log('Please slow down, you request too frequently.')
      return res.sendStatus(429)
    } else {
      redis.setex(requestKey, options.TimeFrameInMinutes * 60, ++info.reqnum, function (err) {
        if (err) {
          return errHandler(err)
        }
        return next()
      })
    }
  }
  redis.get(requestKey, function (err, reqnum) {
    if (err) {
      return errHandler(err)
    }
    reqnum = parseInt(reqnum, 10) || 0
    var too_often = false
    var remaining = options.maxUserRequestLimitPerTimeFrame[req.method] - reqnum
    if (remaining < 0) {
      too_often = true
      res.setHeader('X-Rate-Limit-Reset', resetMinute)
    }
    res.setHeader('X-Rate-Limit-Limit', options.maxUserRequestLimitPerTimeFrame[req.method])
    res.setHeader('X-Rate-Limit-Remaining', Math.max(remaining, 0))
    processResponse({too_often: too_often, reqnum: reqnum || 0})
  })
}
function checkReqsIntensivity ( req , res , next ) { var user_id = req . user && req . user . id ? req . user . id : 0 var ip = req . headers [ 'x-forwarded-for' ] || req . connection . remoteAddress || req . socket . remoteAddress var minute = parseInt ( Date . now ( ) / 1000 / ( options . TimeFrameInMinutes * 60 ) , 10 ) var requestKey = 'RateLimitter:' + ( user_id || ip ) + ':' + req . method + ':' + minute var resetMinute = minute * ( options . TimeFrameInMinutes * 60 ) + ( options . TimeFrameInMinutes * 60 ) function errHandler ( err ) { console . log ( 'RateLimitter Error' ) console . log ( err ) return next ( ) } function processResponse ( info ) { if ( info . too_often ) { console . log ( 'Please slow down, you request too frequently.' ) return res . sendStatus ( 429 ) } else { redis . setex ( requestKey , options . TimeFrameInMinutes * 60 , ++ info . reqnum , function ( err ) { if ( err ) { return errHandler ( err ) } return next ( ) } ) } } redis . get ( requestKey , function ( err , reqnum ) { if ( err ) { return errHandler ( err ) } reqnum = parseInt ( reqnum , 10 ) || 0 var too_often = false var remaining = options . maxUserRequestLimitPerTimeFrame [ req . method ] - reqnum if ( remaining < 0 ) { too_often = true res . setHeader ( 'X-Rate-Limit-Reset' , resetMinute ) } res . setHeader ( 'X-Rate-Limit-Limit' , options . maxUserRequestLimitPerTimeFrame [ req . method ] ) res . setHeader ( 'X-Rate-Limit-Remaining' , Math . max ( remaining , 0 ) ) processResponse ( { too_often : too_often , reqnum : reqnum || 0 } ) } ) }
Checks requests intensivity from single User (if any) OR IP address
 And skips check in we are in development mode
 @param req
 @param res
 @param next
 @returns next()
Checks requests intensivity from single User ( if any ) OR IP address And skips check in we are in development mode @param req @param res @param next @returns next ()
// next minute // save reqnum into redis