@borrowdev/node
v0.2.0
Published
<p align="center"> <a href="https://www.npmjs.com/package/@borrowdev/node"><img src="https://img.shields.io/npm/v/@borrowdev/node" alt="NPM version"></a> <a href="https://jsr.io/@borrow/node"><img src="https://jsr.io/badges/@borrow/node" alt="JSR vers
Readme
Borrow Node.js SDK
[!WARNING]
This package is NOT stable yet. There may be breaking changes with every minor release.It is recommended to wait for the 1.0.0 release before using this package in production.
Features
- Self-hostable - Easily deploy on your own infrastructure
- Minimal dependencies - Lightweight and secure
- Fully typed - Complete TypeScript + JSDoc support
- Simple API - Intuitive interfaces for all tools
- Serverless-first - Integration with modern cloud environments
Installation
# npm
npm install @borrowdev/node
# pnpm
pnpm add @borrowdev/node
# yarn
yarn add @borrowdev/node
# bun
bun add @borrowdev/nodeAuthentication
Usage
Let's use the fixed window algorithm to rate limit our login endpoint to 10 requests per minute.
import { borrow } from "@borrowdev/node";
const { success, timeLeft } = await borrow.limiter("my-limiter-id", "current-user-id", {
limiters: [{
maxRequests: 10,
interval: "minute",
type: "fixed",
}]
});
if (!success) {
return { message: "Rate limit exceeded." + timeLeft !== null ? ` You can try again in ${timeLeft} seconds.` : "" };
}