Skip to content

tinyhttp/bot-detector

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

13 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

@tinyhttp/bot-detector

npm (scoped) npm GitHub Workflow Status Coverage Codacy grade

Bot detector middleware for Node.js based on isbot.

Note that it only shows if a request comes from a bot (e.g. crawler) or from a real human.

Install

pnpm i @tinyhttp/bot-detector

Examples

Vanilla

import { createServer } from 'http'
import { botDetector, RequestWithBotDetector } from '@tinyhttp/bot-detector'

createServer((req, res) => {
  botDetector(req as RequestWithBotDetector, res, () => {
    res.send((req as RequestWithBotDetector).isBot ? `Bot detected πŸ€–: ${req.botName}` : 'Hello World!')
  })
}).listen(3000)

tinyhttp

import { App } from '@tinyhttp/app'
import { botDetector, RequestWithBotDetector } from '@tinyhttp/bot-detector'

new App<any, RequestWithBotDetector>()
  .use(botDetector())
  .use((req, res) => {
    res.send(req.isBot ? `Bot detected πŸ€–: ${req.botName}` : 'Hello World!')
  })
  .listen(3000)