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 🙏

© 2024 – Pkg Stats / Ryan Hefner

librecaptcha

v0.0.5

Published

librecaptcha renders and verifies reCAPTCHA captchas.

Downloads

4

Readme

librecaptcha

librecaptcha renders and verifies reCAPTCHA captchas.

Installation

Via git:

$ git clone https://github.com/nkcmr/librecaptcha.git

Setup

Before you can use this module, you must visit http://www.google.com/recaptcha to request a public and private API key for your domain.

This package has no external dependencies.

Usage

To get started, use require to load recaptcha in your script.

var reCAPTCHA = require("librecaptcha");

Next, initialize a recaptcha singleton that will be used throughout your script.

var captcha = new reCAPTCHA({
    public_key: "pub_key",
    private_key: "private_key"
});

Cool! Now you are ready to generate form snippets and verify submissions!

API

reCAPTCHA

Exposed by require("librecaptcha")

reCAPTCHA(config:Object)

Create a new instance of reCAPTCHA. Available options are as follows:

  • public_key The public key provided by the reCAPTCHA website (see Setup)
  • private_key The private key provided by the reCAPTCHA website (see Setup)

captcha.generate()

Renders and returns a reCAPTCHA snippet as a string.

captcha.verify(recaptcha_data:Object, callback:Function)

Takes in and sends verification request to reCAPTCHA API. Then parses response from server then calls callback. If verification fails, callback will be called with the reason for failure as the first parameter.

The recaptcha_data object contains the following items:

  • remoteip The IP address of the client submitting a reCAPTCHA
  • challenge The parameter sent by the client-side form, it should be sent by the form as recaptcha_challenge_field
  • response The parameter sent by the client-side form, it should be sent by the form as recaptcha_response_field

Example:

var recaptcha_data = {
    remoteip: "74.125.131.113",
    challenge: req.body.recaptcha_challenge_field,
    response: req.body.recaptcha_response_field
};

captcha.verify(recaptcha_data, function(err){
    if(err) {
        // Error Code Reference - https://developers.google.com/recaptcha/docs/verify
        console.error(err);
        if(err == "incorrect-captcha-sol") {
            res.send("you failed!!");
        }
        return;
    }
    // If no error, continue! User has correctly entered the captcha
    res.send("w00t!");
});

Example Using Express

app.js:

var express = require('express');
var reCAPTCHA = require('librecaptcha');
var http = require("http");

var PUBLIC_KEY  = 'public_key';
var PRIVATE_KEY = 'private_key';

var captcha = new reCAPTCHA({
    public_key: PUBLIC_KEY,
    private_key: PRIVATE_KEY
});

var app = express();

app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.bodyParser());

// Routes
app.get('/', function(req, res) {
    res.render('form', {
        recaptcha_form: captcha.generate()
    });
});

app.post('/', function(req, res) {
    var recaptcha_data = {
            remoteip:  req.ip,
            challenge: req.body.recaptcha_challenge_field,
            response:  req.body.recaptcha_response_field
    };

    captcha.verify(recaptcha_data, function(err) {
        if(err) {
            return res.render('form', {
                recaptcha_form: captcha.toHTML()
            });
        }

        console.log("captcha was entered correctly");
        res.send("yay!");
    });
});

http.createServer(app).listen(8080);

views/form.jade:

form(method='POST', action='/')
  != recaptcha_form
  input(type='submit', value='Check Recaptcha')

Make sure express and jade are installed, then:

$ node app.js

The MIT License (MIT)

Copyright (c) 2013 Nick Comer

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.