Package Exports
- node-grecaptcha-verify
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (node-grecaptcha-verify) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
ReCAPTCHA verifier for nodeJS
Implementation of Google reCAPTCHA verify for nodeJS, written in TypeScript. No dependencies. This lib targets reCAPTCHA v3.
Installation
You need to register your website for Google reCAPTCHA to obtain a pair of keys first.
Google will give you a SITE KEY and a SECRET KEY. The SITE KEY is used on your website to
request a token. To verify the token with this lib, you must use the SECRET KEY.
Install the npm package:
$ npm i --save node-grecaptcha-verifyUsage:
import {ReCAPTCHA} from "node-grecaptcha-verify";
const grec = new ReCAPTCHA(<YOUR SITE KEY>);
const isHuman = await grec.verify(<TOKEN>);
if (true === isHuman) {
// requested by a human
} else {
// requested by a bot
}
If you want to know what Google answered (e.g. to check for errors or get the score):
// get the score
const score = grec.lastResponse.score;
// get errors
const errors = greg.lastResponse["error-codes"];
By default, a score lower than 0.5 is considered a bot. You can set your own threshold by
setting it in the constructor. You can also control if the action should be respected and checked.
// set the minimum score for humans to 0.7 (defaults to 0.5)
const grec = new ReCAPTCHA(<YOUR SITE KEY>, 0.7);
// tell the lib to check the action if given to the verify call (defaults to false)
const grec = new ReCAPTCHA(<YOUR SITE KEY>, 0.7, true);
const isHuman = await grec.verify(<TOKEN>, <ACTION>);
License
MIT License