{"id":18353,"library":"express-recaptcha","title":"express-recaptcha","description":"Express middleware for Google reCAPTCHA integration (v2 and v3). Current stable version is 5.1.0, with TypeScript support added in v4.0.0. The library provides simple middleware methods to render captcha widgets and verify tokens. v3.0.0 introduced breaking changes: the module now exports a class constructor instead of an instance, the 'recaptcha' property is set on the response object rather than the request, and the verify result format changed. Alternative packages include 'recaptcha-v2' and 'google-recaptcha', but express-recaptcha offers a straightforward express-centric API.","status":"active","version":"5.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/pdupavillon/express-recaptcha","tags":["javascript","express","nodejs","recaptcha","google","captcha","jade","typescript"],"install":[{"cmd":"npm install express-recaptcha","lang":"bash","label":"npm"},{"cmd":"yarn add express-recaptcha","lang":"bash","label":"yarn"},{"cmd":"pnpm add express-recaptcha","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency; middleware is designed to work with express","package":"express","optional":false}],"imports":[{"note":"Since v4.0.0, library ships TypeScript types. Use named import for RecaptchaV3 or RecaptchaV2. CommonJS require will not work with default export; use .RecaptchaV3.","wrong":"const RecaptchaV3 = require('express-recaptcha')","symbol":"RecaptchaV3","correct":"import { RecaptchaV3 } from 'express-recaptcha'"},{"note":"If using CommonJS, correct import is: const { RecaptchaV2 } = require('express-recaptcha').","wrong":"const Recaptcha = require('express-recaptcha')","symbol":"RecaptchaV2","correct":"import { RecaptchaV2 } from 'express-recaptcha'"},{"note":"v3.0.0+ removed the 'init' function. Use constructor directly.","wrong":"Recaptcha.init('site_key', 'secret_key')","symbol":"init","correct":"const recaptcha = new RecaptchaV3('site_key', 'secret_key')"}],"quickstart":{"code":"import { RecaptchaV3 } from 'express-recaptcha';\nimport express from 'express';\n\nconst app = express();\nconst recaptcha = new RecaptchaV3(process.env.RECAPTCHA_SITE_KEY ?? '', process.env.RECAPTCHA_SECRET_KEY ?? '');\n\napp.use(express.urlencoded({ extended: false }));\napp.use(express.json());\n\napp.get('/', recaptcha.middleware.render, (req, res) => {\n  res.send(`<html><body>${res.recaptcha}</body></html>`);\n});\n\napp.post('/verify', recaptcha.middleware.verify, (req, res) => {\n  if (req.recaptcha.error) {\n    return res.send(`Verification failed: ${req.recaptcha.error}`);\n  }\n  res.send('Success');\n});\n\napp.listen(3000);","lang":"typescript","description":"Shows how to use RecaptchaV3 middleware to render captcha and verify token in Express routes."},"warnings":[{"fix":"Replace Recaptcha.init(site, secret) with new Recaptcha(site, secret).","message":"v3.0.0: express-recaptcha now returns a class instead of an instance; the 'init' function is removed. All parameters must be passed to the constructor.","severity":"breaking","affected_versions":">=3.0.0 <4.0.0"},{"fix":"Update your templates to use res.recaptcha instead of req.recaptcha.","message":"v3.0.0: The render method now sets the 'recaptcha' property on the response object (res.recaptcha) instead of the request object (req.recaptcha).","severity":"breaking","affected_versions":">=3.0.0 <4.0.0"},{"fix":"Refer to v3 changelog for updated verify result format.","message":"v3.0.0: The object returned from the verify middleware has changed; check new structure.","severity":"breaking","affected_versions":">=3.0.0 <4.0.0"},{"fix":"No action needed; but if using @types/express-recaptcha, remove it.","message":"v4.0.0: TypeScript definitions are now included.","severity":"deprecated","affected_versions":">=4.0.0"},{"fix":"Use named import or destructure the require result.","message":"The CommonJS require returns an object with named exports; default import is not available. Use const { RecaptchaV3 } = require('express-recaptcha');","severity":"gotcha","affected_versions":">=4.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Use: const { RecaptchaV3 } = require('express-recaptcha'); then new RecaptchaV3(...).","cause":"Using Recaptcha from CommonJS require without destructuring the named export.","error":"TypeError: Recaptcha is not a constructor"},{"fix":"Ensure you created instance with new RecaptchaV3(site, secret) (v3+).","cause":"The Recaptcha instance was created incorrectly, possibly due to using older API.","error":"recaptcha.middleware.render is not a function"},{"fix":"Run npm install express-recaptcha and check the import statement.","cause":"Package not installed or wrong import path.","error":"Cannot find module 'express-recaptcha'"},{"fix":"Use res.recaptcha in your templates or handlers.","cause":"In v3+, recaptcha is set on response object, not request.","error":"req.recaptcha is undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}