Detect bots among users in your tinyhttp app.
npm install @tinyhttp/bot-detector[![npm (scoped)][npm-badge]](https://npmjs.com/package/@tinyhttp/bot-detector)
[![npm][dl-badge]](https://npmjs.com/package/@tinyhttp/bot-detector)
[![GitHub Workflow Status][gh-actions-img]][github-actions]
![Coverage][codacy-url]
![Codacy grade][codacy-url] 
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.
``sh`
pnpm i @tinyhttp/bot-detector
`ts
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)
`ts
import { App } from '@tinyhttp/app'
import { botDetector, RequestWithBotDetector } from '@tinyhttp/bot-detector'
new App
.use(botDetector())
.use((req, res) => {
res.send(req.isBot ? Bot detected 🤖: ${req.botName} : 'Hello World!')``
})
.listen(3000)
[npm-badge]: https://img.shields.io/npm/v/@tinyhttp/bot-detector?style=for-the-badge&color=hotpink&logo=npm&label=
[dl-badge]: https://img.shields.io/npm/dt/@tinyhttp/bot-detector?style=for-the-badge&color=hotpink
[github-actions]: https://github.com/tinyhttp/bot-detector/actions
[gh-actions-img]: https://img.shields.io/github/actions/workflow/status/tinyhttp/bot-detector/main.yml?branch=master&style=for-the-badge&logo=github&label=&color=hotpink
[codacy-url]: https://www.codacy.com/manual/tinyhttp/bot-detector