https://github.com/meyfa/recaptcha-promise
Node module for promise-based ReCAPTCHA verification
https://github.com/meyfa/recaptcha-promise
nodejs npm-package package promise recaptcha-promise recaptcha-verification
Last synced: about 1 month ago
JSON representation
Node module for promise-based ReCAPTCHA verification
- Host: GitHub
- URL: https://github.com/meyfa/recaptcha-promise
- Owner: meyfa
- License: mit
- Created: 2016-07-17T12:23:10.000Z (over 9 years ago)
- Default Branch: main
- Last Pushed: 2025-09-25T20:28:02.000Z (about 2 months ago)
- Last Synced: 2025-09-25T22:38:16.075Z (about 2 months ago)
- Topics: nodejs, npm-package, package, promise, recaptcha-promise, recaptcha-verification
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/recaptcha-promise
- Size: 707 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# recaptcha-promise
[](https://github.com/meyfa/recaptcha-promise/actions/workflows/main.yml)
[](https://codeclimate.com/github/meyfa/recaptcha-promise/test_coverage)
This Node module aims to provide simple, asynchronous, promise-based ReCAPTCHA
response verification. TypeScript type definitions are included.
_This software is in no way affiliated with or endorsed by Google._
## Installation
Add to your project's dependencies:
```sh
npm install recaptcha-promise
```
## Usage
### Creating an instance
This is the recommended way. First, an instance is created with your secret key.
It can then be used to verify as many challenges as needed.
```js
const recaptcha = require('recaptcha-promise').create({
secret: 'YOUR_SECRET_KEY'
})
// In an HTTP handler:
// ... with Promises:
recaptcha.verify(userResponse).then(function (success) {
console.log(success ? 'Response valid' : 'Response invalid')
})
// ... or in an async context:
async function handleRequest (userResponse) {
const success = await recaptcha.verify(userResponse)
console.log(success ? 'Response valid' : 'Response invalid')
}
handleRequest(/* ... */)
```
### The global instance
This exists mostly for legacy reasons. If you do not want to dependency-inject
a custom object, you can configure this package with your secret key globally:
```js
// note the missing .create(...) call
const recaptcha = require('recaptcha-promise')
recaptcha.init({
secret: 'YOUR_SECRET_KEY' // secret_key and secretKey are also valid
})
```
You can then use `recaptcha` exactly the same as above. You can also require it
elsewhere and it will still have the secret key ready.
### Passing a remote address
If you have the client's remote address available, you can pass it as a second
parameter to the `verify` function.