Skip to content
LimitYourAPI
DocsPricingSolutionsLearnBlogCompare About Security Status Privacy Terms Get Started Free
SDK Documentation

JavaScript SDK Integration

LimitYourAPI JavaScript SDK for Node.js and edge runtimes.

JavaScript SDK Integration Guide

Install the official LimitYourAPI JavaScript SDK to restrict client request rates in Node.js, Express, and modern browser environments. For type-safe applications with full interface definitions, please see the [TypeScript SDK](/sdk/typescript).

1. Installation

`bash

npm install limityourapi

`

2. Simple Usage

Initialize the client and check rate limits inline:

`javascript

import { LimitYourAPIClient } from 'limityourapi';

const limiter = new LimitYourAPIClient({

apiKey: process.env.LIMIT_YOUR_API_KEY

});

const response = await limiter.check({

key: 'user_12345',

route: '/api/resource',

cost: 1

});

if (!response.allowed) {

console.log(Rate limit exceeded! Retry after ${response.retryAfter}s);

}

`

3. Express Middleware Example

Implement rate limiting globally or per-route inside Express:

`javascript

import express from 'express';

import { LimitYourAPIClient } from 'limityourapi';

const app = express();

const limiter = new LimitYourAPIClient({

apiKey: process.env.LIMIT_YOUR_API_KEY

});

const rateLimitMiddleware = async (req, res, next) => {

try {

const key = req.ip;

const decision = await limiter.check({ key, route: req.path });

res.setHeader('X-RateLimit-Limit', decision.limit);

res.setHeader('X-RateLimit-Remaining', decision.remaining);

res.setHeader('X-RateLimit-Reset', decision.reset);

if (!decision.allowed) {

res.setHeader('Retry-After', decision.retryAfter);

return res.status(429).json({ error: 'Too Many Requests', retryAfter: decision.retryAfter });

}

next();

} catch (error) {

console.error('Rate limit error:', error);

next();

}

};

app.use('/api/', rateLimitMiddleware);

`

4. Production Checklist

Rate Limiting Glossary

Understanding rate limiting terminology helps teams communicate requirements clearly across engineering, product, and security teams for JavaScript SDK.

Term Definition
Rate limit Maximum number of requests allowed in a time window
Quota Total allowed usage over a longer period (daily, monthly)
Token bucket Algorithm allowing bursts up to bucket capacity with steady refill
Sliding window Counts requests in a rolling time window for precise enforcement
Fail-open Allow requests when rate limiter is unreachable
Fail-closed Reject requests when rate limiter is unreachable
429 HTTP Status Standard HTTP status code for rate limit exceeded
Retry-After Header indicating seconds until client should retry
Identifier / Key Unique string identifying the client for rate limiting
Express Middleware In-app route handler that intercepts incoming Node requests
Event Loop Single-threaded execution loop in Node.js that must remain non-blocking
Async Caching Non-blocking execution hooks validating keys concurrently

Next Steps

Ready to protect your API with production-grade rate limiting? Here is the recommended path for JavaScript SDK:

  1. Create a free account at [limityourapi.tech/login](/login) — no credit card required for the Hobby tier
  2. Generate an API key in the dashboard under API Keys
  3. Install the SDK: Run npm install limityourapi and follow the [Node.js](/sdk/nodejs) guide
  4. Follow the quick start guide at [/quickstart](/quickstart) for a 2-minute integration
  5. Configure rules in the dashboard for your highest-risk endpoints first
  6. Monitor analytics to tune limits based on real traffic patterns

Questions? Read the [documentation](/docs) or explore the [rate limiting education hub](/learn) for deep technical guides on algorithms, architecture, and production patterns.

Frequently Asked Questions

What is API rate limiting?

API rate limiting controls how many requests a client can make in a given time window. It protects backends from abuse, ensures fair usage across tenants, and prevents cost overruns from traffic spikes or malicious bots.

Why use Redis for rate limiting?

Redis provides sub-millisecond latency, atomic operations via Lua scripts, and horizontal scalability. Centralized state ensures consistent limits across distributed application servers.

How fast is LimitYourAPI?

LimitYourAPI delivers rate limit decisions in under 15ms globally using atomic Redis Lua scripts. This is fast enough for inline middleware without adding perceptible latency to API responses.

Does LimitYourAPI support token bucket and sliding window?

Yes. LimitYourAPI supports token bucket, sliding window, fixed window, and cost-aware algorithms. You can configure per-route strategies without changing infrastructure.

Can I migrate from express-rate-limit or Cloudflare?

Yes. LimitYourAPI provides migration guides with before/after code examples for express-rate-limit, Cloudflare, Upstash, Arcjet, and other providers.

Protect your API in minutes

Join developers using LimitYourAPI for sub-millisecond Redis-backed rate limiting.