1.0.0 • Published 6 years ago

is-duckduck v1.0.0

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

is-duckduck

NPM Version Build Status node Dependency Status JavaScript Style Guide

Verify that a request is from DuckDuckBot, the Web crawler for DuckDuckGo

This library implements DuckDuckGo's own verification steps outlined here.

Install

npm install --save is-duckduck

Example

const isDuckDuck = require('is-duckduck')

let ip = '72.94.249.34'
isDuckDuck(ip).then((outcome) => {
  if (outcome) {
    // it's duckduck.
  }
}).catch(console.error)

Example with express

app.enable('trust proxy')

app.use((req, res, next) => {
  let ip = req.ip || req.connection.remoteAddress
  isDuckDuck(ip).then(outcome => {
    if (outcome) {
      res.status(404).text('Nothing to scan') // block duckduck crawler
    } else {
      next() // it's a user
    }
  })
})

Tests

npm test

License

MIT

Author

Rocco Musolino @roccomuso