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);
sdk: Inform type signature of protect via global characteristics (#1043) (1ae4a89), closes #1042
📦 Dependencies
Bump @typescript-eslint/eslint-plugin from 7.13.0 to 7.13.1 (#994) (9481c7f)
Bump @typescript-eslint/eslint-plugin from 7.13.1 to 7.14.1 (#1025) (7e8cc60)
Bump @typescript-eslint/parser from 7.13.0 to 7.13.1 (#993) (d15a09d)
Bump @typescript-eslint/parser from 7.13.1 to 7.14.1 (#1024) (ee81b09)
Bump eslint-config-turbo from 2.0.4 to 2.0.5 (#1023) (aaaf17c)
Bump eslint-config-turbo from 2.0.5 to 2.0.6 (#1052) (e1d3cd3)
dev: Bump bun-types from 1.1.13 to 1.1.17 (#1022) (3aa7181)
dev: Bump typescript from 5.4.5 to 5.5.2 (#1011) (c17a101)
example: Bump @clerk/nextjs from 5.1.5 to 5.1.6 in /examples/nextjs-14-clerk-rl in the dependencies group (#1013) (8bed1dc)
example: Bump @clerk/nextjs from 5.1.5 to 5.1.6 in /examples/nextjs-14-clerk-shield in the dependencies group (#1012) (c4bcde8)
example: Bump @sveltejs/kit from 2.5.17 to 2.5.18 in /examples/sveltekit in the dependencies group (#1046) (ebab7de)
example: Bump ai from 3.1.36 to 3.1.37 in /examples/nextjs-14-openai in the dependencies group (#995) (b43827b)
example: Bump hono from 4.4.9 to 4.4.10 in /examples/nodejs-hono-rl in the dependencies group (#1048) (6e7c1fe)
example: Bump lucide-react from 0.396.0 to 0.399.0 in /examples/nextjs-14-authjs-5 in the dependencies group across 1 directory (#1040) (ea96487)
example: Bump lucide-react from 0.396.0 to 0.399.0 in /examples/nextjs-14-react-hook-form in the dependencies group across 1 directory (#1039) (334ff9e)
example: Bump postcss from 8.4.38 to 8.4.39 in /examples/nextjs-14-app-dir-rl in the dependencies group (#1051) (ac24a0b)
example: Bump postcss from 8.4.38 to 8.4.39 in /examples/nextjs-14-app-dir-validate-email in the dependencies group (#1045) (290bc49)
example: Bump postcss from 8.4.38 to 8.4.39 in /examples/nextjs-14-authjs-5 in the dependencies group (#1056) (e2343f0)
example: Bump postcss from 8.4.38 to 8.4.39 in /examples/nextjs-14-clerk-rl in the dependencies group (#1058) (422b320)
example: Bump postcss from 8.4.38 to 8.4.39 in /examples/nextjs-14-clerk-shield in the dependencies group (#1044) (b6b891f)
example: Bump postcss from 8.4.38 to 8.4.39 in /examples/nextjs-14-decorate in the dependencies group (#1049) (43523a5)
example: Bump postcss from 8.4.38 to 8.4.39 in /examples/nextjs-14-ip-details in the dependencies group (#1047) (1fe6a05)
example: Bump postcss from 8.4.38 to 8.4.39 in /examples/nextjs-14-nextauth-4 in the dependencies group (#1054) (caff3dc)
example: Bump postcss from 8.4.38 to 8.4.39 in /examples/nextjs-14-pages-wrap in the dependencies group (#1055) (90e04f5)
example: Bump postcss from 8.4.38 to 8.4.39 in /examples/nextjs-14-react-hook-form in the dependencies group (#1050) (21e1108)
example: Bump the dependencies group across 1 directory with 2 updates (#1006) (0578cb2)
example: Bump the dependencies group across 1 directory with 2 updates (#1019) (a15df12)
example: Bump the dependencies group across 1 directory with 6 updates (#1017) (fb43c78)
example: Bump the dependencies group across 1 directory with 7 updates (#1028) (a3693d0)
example: Bump the dependencies group across 1 directory with 7 updates (#1036) (4e2bfe9)
example: Bump the dependencies group in /examples/nextjs-14-openai with 2 updates (#1057) (5df2e47)
example: Bump the dependencies group in /examples/nextjs-14-react-hook-form with 2 updates (#996) (988dbf3)
example: Bump the dependencies group in /examples/nodejs-hono-rl with 2 updates (#1007) (c36b9f3)
Move generated protobuf to default buf file path (#1009) (6800a00)
Warn when IP is empty, even if we override it in development (#1000) (da14bcb), closes #987#216
FAQs
Arcjet SDK for Node.js
The npm package @arcjet/node receives a total of 80 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 2 open source maintainers collaborating on the project.
Package last updated on 01 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 2023 Python Developers Survey reveals key trends in packaging, web frameworks, and developer demographics, highlighting a shift toward innovative tools as the Python community diversifies and grows among less experienced developers.
GitHub is combatting a new spam campaign that exploits issues with links to malicious downloads, highlighting the need for better moderation tools to protect open-source maintainers' time and security.
uv, Python's new package manager, offers a faster and more efficient alternative to pip with features that simplify tooling, manage Python versions, and streamline development workflows.