Turnstile for NestJS

nest-cloudflare-turnstile is an open-source NestJS module I've maintained since 2024. It asks Cloudflare whether a Turnstile token is real before your handlers run.

Read the docsnpmRead the walkthrough

5,159
npm downloads in the last 30 days1

Sources

  1. npm, downloads of nest-cloudflare-turnstile, 29 Oct 2026 – 27 Nov 2026. Read from npm when the page is built.

The problem

The Turnstile widget on its own protects nothing: a bot can skip the page and post straight to the API. The server-side check is where people slip. They check the token in one controller, forget it in the next, or skip the hostname check.

Who it's for

NestJS developers who put Turnstile in front of logins, sign-ups and forms, on Express or Fastify, including GraphQL resolvers and WebSocket gateways.

Decisions that shaped it

  • A guard, not a helper call

    The check runs in a NestJS guard, so it happens before any handler and lives in one place. One decorator covers a route or a controller, or a global guard with @SkipTurnstile() for the exceptions.

  • Nothing to install but Nest

    Since 1.0 the module has no runtime dependencies besides Nest itself, and it calls Cloudflare with the fetch built into Node.js.

  • Secrets never leak into errors

    Errors and debug logs leave out tokens and secret keys, and an optional startup check confirms that Cloudflare accepts your key.

  • One retry, then a clear answer

    When Cloudflare reports an internal error, the guard retries once. Calls time out after five seconds instead of hanging a request.

What shipped

  1. First version on npm.

  2. 1.0, 1.1 and 1.2 in one day: NestJS 10, 11 and 12, no runtime dependencies, hostname and action checks, several widgets, WebSocket gateways and an onVerify hook.

  3. A full walkthrough on this blog, with real responses from the module's example app.

More products