0.5.1 • Published 6 years ago

datadome-client v0.5.1

Weekly downloads
6
License
MIT
Repository
github
Last release
6 years ago

datadome-client

MIT Licence Dependencies

A node.js module for accessing Datadome API.

Datadome ?

« DataDome detects non-human traffic, identifies and categorizes in real time bot operators »

Prerequisites

Open an account and ask your API Key (free trial 30 days) https://datadome.co/free-signup/

Installation

npm install datadome-client

Usage

Express/Connect

const app = require('express')();
const Datadome = require('datadome-client');
const datadomeClient = new Datadome({apiKey:'YOURAPIKEY'});

app.use(function(req, res, next) {
    datadomeClient.isBot(req,(err, result) => {

        if (err) {
            // if an error occured with datadome,
            // let's continue
            return next();
        }

        if (!result.isBot) {
            // not a bot, continue
            return next();
        }

        /**
         * bot detected, let's handle response.
         * in this example, we block the request with a message,
         * but in real life, you should log, then make the bad bot wait
         * for the response (setTimeout), and/or redirect somewhere else, ...
         **/

        res
            .status(result.response)
            .send("Sorry "+result.botname+", you are a "+result.botfamily+", and you are not welcome here.")
            .end();
    })
});