npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@startupjs/recaptcha

v0.61.0

Published

reCAPTCHA plugin

Readme

@startupjs/recaptcha

library for displaying and interacting with Google ReCaptcha

Install the module

yarn add @startupjs/recaptcha

Init module on server

Add the following lines to server/index.js:

  import initRecaptcha from '@startupjs/recaptcha/server'

Add to the startupjsServer function:

  initRecaptcha(ee, options)

The options argument accepts an object with a type field, that specify which reCAPTCHA type you want to use (possible types: enterprise or v3)

In the getHead function, add a call to the getRecaptchaHead function:

  import { getRecaptchaHead } from '@startupjs/recaptcha/server'

  function getHead (req) {
    return `
      // ...
      ${getRecaptchaHead(req)}
      // ...
    `
}

Configuring config.json

In config.json file of your project, you need to add for reCAPTCHA Enterprise:

  {
    "RECAPTCHA_SECRET_KEY": "YOUR_SECRET_KEY",
    "RECAPTCHA_ENTERPRISE_NORMAL_SITE_KEY": "YOUR_SITE_KEY",
    "RECAPTCHA_ENTERPRISE_INVISIBLE_SITE_KEY": "YOUR_SITE_KEY",
    "GOOGLE_CLOUD_PROJECT_ID": "ID_YOUR_CLOUD_PROJECT"
  }

RECAPTCHA_SECRET_KEY created here https://console.cloud.google.com/apis/credentials RECAPTCHA_ENTERPRISE_NORMAL_SITE_KEY и RECAPTCHA_ENTERPRISE_INVISIBLE_SITE_KEY - https://cloud.google.com/recaptcha-enterprise/docs/create-key

For reCAPTCHA v3, it will be enough:

  {
    "RECAPTCHA_SECRET_KEY": "YOUR_SECRET_KEY",
    "RECAPTCHA_SITE_KEY": "YOUR_SITE_KEY"
  }

These keys are created in the Google Admin Console.

Usage

Client

  import { Recaptcha } from '@startupjs/recaptcha'
  const [recaptchaVerified, setRecaptchaVerified] = useState(false)
  const [email, setEmail] = useState('')

  const ref = useRef()

  const openRecaptcha = () => {
    if (!email) return

    ref.current.open()
  }

  const onVerify = async recaptcha => {
    try {
      const res = await axios.post('/api/subscribe-to-mailing', {
        recaptcha,
        email
      })
      console.log('Response: ', res.data)
      setRecaptchaVerified(res.data)
    } catch (err) {
      console.error(err.response.data)
    }
  }

  return pug`
    Div.root
      TextInput.emailInput(
        label='Your email'
        value=email
        onChangeText=setEmail
      )
      Recaptcha(
        ref=ref
        onVerify=onVerify
        onLoad=() => console.log('onLoad')
        onExpire=() => console.log('onExpire')
        onError=error => console.log('onError', error)
        onClose=() => console.log('onClose')
      )
      if recaptchaVerified
        Span.label Thank you for subscribing
      Button(
        onPress=openRecaptcha
        disabled=recaptchaVerified
      ) Subscribe
  `

Server

import { checkRecaptcha } from '@startupjs/recaptcha/server'

export default function initRoutes (router) {
  router.post('/api/subscribe-to-mailing', async function (req, res) {
    const { recaptcha, email } = req.body

    const isVerified = await checkRecaptcha(recaptcha)

    if (!isVerified) {
      return res.status(403).send(isVerified)
    }

    // Do something with email subscription...
  })
}

Recaptcha component props

The Recaptcha component takes parameters from official Google reCAPTCHA documentation

  • variant [String] - The variant of the widget (invisible, normal or compact). Default: invisible
  • theme [String] - The color theme of the widget (dark or light). Default: light
  • baseUrl [String] - The URL (domain) configured in the reCAPTCHA setup. (ex. http://my.domain.com). Default: your BASE_URL from @env
  • lang [String] - Language code. Default: en
  • onLoad [Function] - A callback function, executed when the reCAPTCHA is ready to use
  • onVerify [Function(token)] - A callback function, executed when the user submits a successful response. The recaptcha response token is passed to your callback
  • onExpire [Function] - A callback function, executed when the reCAPTCHA response expires and the user needs to re-verify
  • onError [Function(error)] - A callback function, executed when reCAPTCHA encounters an error (usually network connectivity) and cannot continue until connectivity is restored. If you specify a function here, you are responsible for informing the user that they should retry
  • onClose [Function] - (Experimental) A callback function, executed when the Modal is closed

Advanced use

  import { checkDataRecaptcha } from '@startupjs/recaptcha/server'

checkDataRecaptcha(recaptcha) is an advanced variant of checkRecaptcha(recaptcha) function that returns an object with the original Google API response. Different reCAPTCHA types return different data structures in the response.