a simple google recaptcha api library to validate recaptchas

Downloads in past


102.0.06 years ago8 years agoMinified + gzip package size for recaptcha-validator in KB


A simple library that makes API requests to Google's Recaptcha service to confirm Recaptcha tokens.

Supports Recaptcha v2 / Invisible.
const recaptcha = require('recaptcha-validator')

recaptcha(sitesecret, gRecaptchaResponse, clientIpAddress)
  .then(reply => console.log(reply))
  .catch(err => console.error('recaptcha confirmation failed:', err))


Check out the example/ folder for a complete but minimal example.
recaptcha() returns a promise that resolves with google's reply if the request was successful.
It fails with typeof err === 'string' if the recaptcha api reports a problem with the request.
  • missing-input-secret: The secret parameter is missing.
  • invalid-input-secret: The secret parameter is invalid or malformed.
  • missing-input-response: The response parameter is missing.
  • invalid-input-response: The response parameter is invalid or malformed.
  • bad-request: The request is invalid or malformed.
  • unspecified-error

Else the error will be an Error object representing network error.
Here's an example response upon success:
{ success: true,
  challenge_ts: '2017-11-09T23:12:08Z',
  hostname: 'localhost' }

hostname only appears on successful requests and you can use it to ensure recaptcha submissions are originating from your domain.
More info: