### Install Borrow Node.js Package Source: https://github.com/borrowdev/borrow/blob/main/apps/docs/src/app/limiter/quick-start/page.mdx Installs the Borrow Node.js package using different package managers. This is the first step to integrate Borrow Limiter into your Node.js application. ```bash npm install @borrowdev/node ``` ```bash pnpm add @borrowdev/node ``` ```bash yarn add @borrowdev/node ``` ```bash bun add @borrowdev/node ``` -------------------------------- ### Example: Create Supabase Proxy Project using Borrow CLI Source: https://github.com/borrowdev/borrow/blob/main/apps/README.md An example demonstrating the usage of the `borrow start new` command to create a new project from the 'supabase-proxy' template, outputting it to a specified directory. ```bash borrow start new -t supabase-proxy -o ~/my-awesome-project ``` -------------------------------- ### Implement Sliding Window Rate Limiting with Borrow Source: https://github.com/borrowdev/borrow/blob/main/apps/docs/src/app/limiter/quick-start/page.mdx Demonstrates how to use the Borrow Limiter API with the sliding window algorithm to enforce rate limits. It includes examples in TypeScript, JavaScript, and a curl command for testing. ```TypeScript import { borrow } from "@borrowdev/node"; const { success, timeLeft } = await borrow.limiter("my-limiter-id", "current-user-id", { limiters: [{ maxRequests: 10, interval: "minute", type: "sliding", }] }); if (!success) { return { message: "Rate limit exceeded." + timeLeft !== null ? ` You can try again in ${timeLeft} seconds.` : "" }; } // ... Your expensive business logic ``` ```JavaScript import { borrow } from "@borrowdev/node"; const { success, timeLeft } = await borrow.limiter("my-limiter-id", "current-user-id", { limiters: [{ maxRequests: 10, interval: "minute", type: "sliding", }] }); if (!success) { return { message: "Rate limit exceeded." + timeLeft !== null ? ` You can try again in ${timeLeft} seconds.` : "" }; } // ... Your expensive business logic ``` ```curl curl https://api.borrow.dev/v1/limiter \ --request POST \ --header 'Content-Type: application/json' \ --data '{ "userId": "current-user-id", "key": "login", "limiters": [ { "type": "sliding", "maxRequests": 10, "interval": "minute" } ] }' ``` -------------------------------- ### Install Borrow and Redis Dependencies Source: https://github.com/borrowdev/borrow/blob/main/apps/docs/src/app/limiter/self-hosting/page.mdx Installs the necessary npm packages for the Borrow Limiter and Upstash Redis adapter. This command is essential for setting up the project environment. ```bash npm install @borrowdev/node @upstash/redis ``` -------------------------------- ### Borrow CLI Usage Examples Source: https://github.com/borrowdev/borrow/blob/main/README.md Provides examples of how to use the Borrow CLI to manage templates. This includes commands to download and install a new template from the Borrow registry or a local path, and to delete a cached template. ```bash # Download and install a template borrow start new -t