@tinyhttp/bot-detector

Detect bots among users in your tinyhttp app.

Usage no npm install needed!

<script type="module">
  import tinyhttpBotDetector from 'https://cdn.skypack.dev/@tinyhttp/bot-detector';
</script>

README

@tinyhttp/bot-detector

npm (scoped) npm

Detect bots among users in your tinyhttp app. This middlewares is based on isbot.

Note that it doesn't differentiate "good" and "bad" bots, it only shows if a request comes from a bot (e.g. crawler) or from a real human.

Install

pnpm i @tinyhttp/bot-detector

API

botDetector()(req, res)

This middleware adds 2 new getters, isBot and botName.

  • isBot is a boolean which shows if the request is made by a bot
  • botName is a string that shows the bot name in case isBot is true.

Both getters are lazy and will not be calculated until needed

Example

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

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