Arcjet helps developers protect their apps in just a few lines of
code. Implement rate limiting, bot protection, email verification, and defense
against common attacks.
The Arcjet rate limit example below applies a token
bucket rate limit rule to a route where we identify the user based on their ID
e.g. if they are logged in. The bucket is configured with a maximum capacity of
10 tokens and refills by 5 tokens every 10 seconds. Each request consumes 5
tokens.
import arcjet, { tokenBucket } from"@arcjet/node";
import http from"node:http";
const aj = arcjet({
key: process.env.ARCJET_KEY!, // Get your site key from https://app.arcjet.comrules: [
// Create a token bucket rate limit. Other algorithms are supported.tokenBucket({
mode: "LIVE", // will block requests. Use "DRY_RUN" to log onlycharacteristics: ["userId"], // track requests by a custom user IDrefillRate: 5, // refill 5 tokens per intervalinterval: 10, // refill every 10 secondscapacity: 10, // bucket maximum capacity of 10 tokens
}),
],
});
const server = http.createServer(asyncfunction (
req: http.IncomingMessage,
res: http.ServerResponse,
) {
const userId = "user123"; // Replace with your authenticated user IDconst decision = await aj.protect(req, { userId, requested: 5 }); // Deduct 5 tokens from the bucketconsole.log("Arcjet decision", decision);
if (decision.isDenied()) {
res.writeHead(429, { "Content-Type": "application/json" });
res.end(
JSON.stringify({ error: "Too Many Requests", reason: decision.reason }),
);
} else {
res.writeHead(200, { "Content-Type": "application/json" });
res.end(JSON.stringify({ message: "Hello world" }));
}
});
server.listen(8000);
Shield example
Arcjet Shield protects your application against common
attacks, including the OWASP Top 10. You can run Shield on every request with
negligible performance impact.
import arcjet, { shield } from"@arcjet/node";
import http from"node:http";
const aj = arcjet({
key: process.env.ARCJET_KEY!, // Get your site key from https://app.arcjet.comrules: [
shield({
mode: "LIVE", // will block requests. Use "DRY_RUN" to log only
}),
],
});
const server = http.createServer(asyncfunction (
req: http.IncomingMessage,
res: http.ServerResponse,
) {
const decision = await aj.protect(req);
if (decision.isDenied()) {
res.writeHead(403, { "Content-Type": "application/json" });
res.end(JSON.stringify({ error: "Forbidden" }));
} else {
res.writeHead(200, { "Content-Type": "application/json" });
res.end(JSON.stringify({ message: "Hello world" }));
}
});
server.listen(8000);
detect common free/disposable email providers locally (#1096) (115d016), closes #1095
📦 Dependencies
Bump @typescript-eslint/eslint-plugin from 7.14.1 to 7.15.0 (#1063) (d4a1cfe)
Bump @typescript-eslint/eslint-plugin from 7.15.0 to 7.16.0 (#1091) (6bbcbe6)
bump @typescript-eslint/eslint-plugin from 7.16.0 to 7.16.1 (#1135) (6f4495a)
Bump @typescript-eslint/parser from 7.14.1 to 7.15.0 (#1064) (b6e2b0f)
Bump @typescript-eslint/parser from 7.15.0 to 7.16.0 (#1090) (c31957f)
bump @typescript-eslint/parser from 7.16.0 to 7.16.1 (#1132) (3feb40a)
Bump typeid-js from 0.7.0 to 1.0.0 (#1079) (fa276c5)
dev: Bump @edge-runtime/jest-environment from 2.3.10 to 3.0.0 (#1087) (1e6eb00)
dev: bump @edge-runtime/jest-environment from 3.0.0 to 3.0.1 (#1123) (9064240)
dev: Bump @rollup/wasm-node from 4.18.0 to 4.18.1 (#1092) (ffc298a)
dev: Bump bun-types from 1.1.17 to 1.1.18 (#1080) (6bb3483)
dev: bump bun-types from 1.1.18 to 1.1.20 (#1118) (dbf3826)
dev: Bump typescript from 5.5.2 to 5.5.3 (#1065) (ef05395)
example: Bump @clerk/nextjs from 5.1.6 to 5.2.2 in /examples/nextjs-14-clerk-rl in the dependencies group across 1 directory (#1082) (7ac1236)
example: Bump @clerk/nextjs from 5.1.6 to 5.2.2 in /examples/nextjs-14-clerk-shield in the dependencies group across 1 directory (#1081) (9b89f9b)
example: bump @clerk/nextjs from 5.2.2 to 5.2.3 in /examples/nextjs-14-clerk-rl in the dependencies group (#1119) (5fe9ef0)
example: bump @clerk/nextjs from 5.2.2 to 5.2.3 in /examples/nextjs-14-clerk-shield in the dependencies group (#1121) (baf55e0)
example: Bump hono from 4.4.11 to 4.4.12 in /examples/nodejs-hono-rl in the dependencies group (#1085) (3782001)
example: Bump hono from 4.4.12 to 4.4.13 in /examples/nodejs-hono-rl in the dependencies group (#1112) (49f8721)
example: Bump lucide-react from 0.399.0 to 0.400.0 in /examples/nextjs-14-authjs-5 in the dependencies group (#1066) (b44dd6a)
example: bump lucide-react from 0.407.0 to 0.408.0 in /examples/nextjs-14-authjs-5 in the dependencies group (#1116) (84bd181)
example: bump tailwindcss from 3.4.4 to 3.4.5 in /examples/nextjs-14-app-dir-rl in the dependencies group (#1124) (c73e955)
example: bump tailwindcss from 3.4.4 to 3.4.5 in /examples/nextjs-14-authjs-5 in the dependencies group (#1129) (74adca7)
example: bump tailwindcss from 3.4.4 to 3.4.5 in /examples/nextjs-14-clerk-rl in the dependencies group (#1125) (8aa2f53)
example: bump tailwindcss from 3.4.4 to 3.4.5 in /examples/nextjs-14-clerk-shield in the dependencies group (#1130) (6f76186)
example: bump tailwindcss from 3.4.4 to 3.4.5 in /examples/nextjs-14-decorate in the dependencies group (#1126) (b2d9a81)
example: bump tailwindcss from 3.4.4 to 3.4.5 in /examples/nextjs-14-ip-details in the dependencies group (#1127) (0251e74)
example: bump tailwindcss from 3.4.4 to 3.4.5 in /examples/nextjs-14-nextauth-4 in the dependencies group (#1128) (b7f0028)
example: bump tailwindcss from 3.4.4 to 3.4.5 in /examples/nextjs-14-pages-wrap in the dependencies group (#1131) (af3f8d6)
example: Bump the dependencies group across 1 directory with 2 updates (#1068) (bc86928)
example: Bump the dependencies group across 1 directory with 2 updates (#1071) (75df78a)
example: bump the dependencies group across 1 directory with 2 updates (#1117) (306d4f1)
example: Bump the dependencies group across 1 directory with 3 updates (#1072) (937b184)
example: Bump the dependencies group across 1 directory with 3 updates (#1108) (3714941)
example: Bump the dependencies group across 1 directory with 4 updates (#1106) (caaea7a)
example: Bump the dependencies group across 1 directory with 6 updates (#1109) (c877b39)
example: Bump the dependencies group in /examples/nextjs-14-app-dir-rl with 2 updates (#1104) (8cbde05)
example: Bump the dependencies group in /examples/nextjs-14-app-dir-validate-email with 2 updates (#1107) (298a70b)
example: Bump the dependencies group in /examples/nextjs-14-clerk-rl with 2 updates (#1102) (f1e7a4c)
example: Bump the dependencies group in /examples/nextjs-14-clerk-shield with 2 updates (#1101) (10184f9)
example: Bump the dependencies group in /examples/nextjs-14-decorate with 2 updates (#1111) (52394af)
example: Bump the dependencies group in /examples/nextjs-14-ip-details with 2 updates (#1105) (5127321)
example: Bump the dependencies group in /examples/nextjs-14-nextauth-4 with 2 updates (#1103) (8ef993f)
example: Bump the dependencies group in /examples/nextjs-14-openai with 2 updates (#1113) (89b3ccb)
example: bump the dependencies group in /examples/nextjs-14-openai with 2 updates (#1133) (d2ac694)
example: Bump the dependencies group in /examples/nextjs-14-pages-wrap with 2 updates (#1110) (fb05224)
example: bump the dependencies group in /examples/nextjs-14-react-hook-form with 2 updates (#1120) (729c886)
example: bump the dependencies group in /examples/nextjs-14-react-hook-form with 2 updates (#1134) (2fbe4d6)
example: Bump the dependencies group in /examples/sveltekit with 2 updates (#1093) (009591a)
example: bump the dependencies group in /examples/sveltekit with 2 updates (#1136) (c93a9eb)
🧹 Miscellaneous Chores
examples: Add example of testing APIs with Newman (#1083) (6b2ccf0)
examples: Show dynamic feature flags with LaunchDarkly (#1100) (d3bf356)
FAQs
Arcjet SDK for Node.js
The npm package @arcjet/node receives a total of 123 weekly downloads. As such, @arcjet/node popularity was classified as not popular.
We found that @arcjet/node demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.It has 0 open source maintainers collaborating on the project.
Package last updated on 15 Jul 2024
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
The Socket Research Team uncovered a malicious Python package typosquatting the popular 'fabric' SSH library, silently exfiltrating AWS credentials from unsuspecting developers.
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
By Kush Pandya, Philipp Burckhardt, Kirill Boychenko, Orlando Barrera - Oct 31, 2024