@tinyhttp/bot-detector
Version:
Detect bots among users in your tinyhttp app.
57 lines (41 loc) • 2.15 kB
Markdown
<div align="center">
[![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]
[][codacy-url]
[][codacy-url] [](https://stakes.social/0x14308514785B216904a41aB817282d25425Cce39)
</div>
Bot detector middleware for Node.js based on [isbot](https://github.com/omrilotan/isbot).
Note that it only shows if a request comes from a bot (e.g. crawler) or from a real human.
## Install
```sh
pnpm i @tinyhttp/bot-detector
```
## Examples
### Vanilla
```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<any, RequestWithBotDetector>()
.use(botDetector())
.use((req, res) => {
res.send(req.isBot ? `Bot detected 🤖: ${req.botName}` : 'Hello World!')
})
.listen(3000)
```
[ ]: https://img.shields.io/npm/v/@tinyhttp/bot-detector?style=for-the-badge&color=hotpink&logo=npm&label=
[ ]: https://img.shields.io/npm/dt/@tinyhttp/bot-detector?style=for-the-badge&color=hotpink
[ ]: https://github.com/tinyhttp/bot-detector/actions
[ ]: https://img.shields.io/github/actions/workflow/status/tinyhttp/bot-detector/main.yml?branch=master&style=for-the-badge&logo=github&label=&color=hotpink
[ ]: https://www.codacy.com/manual/tinyhttp/bot-detector