https://github.com/tinyhttp/bot-detector
🤖 Bot detector for Node.js
https://github.com/tinyhttp/bot-detector
antispam bot-detector esm middleware nodejs nodejs-library nodejs-middleware
Last synced: 2 months ago
JSON representation
🤖 Bot detector for Node.js
- Host: GitHub
- URL: https://github.com/tinyhttp/bot-detector
- Owner: tinyhttp
- License: mit
- Created: 2021-06-23T15:10:01.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2024-01-04T11:09:07.000Z (over 1 year ago)
- Last Synced: 2025-03-24T08:47:19.723Z (3 months ago)
- Topics: antispam, bot-detector, esm, middleware, nodejs, nodejs-library, nodejs-middleware
- Language: TypeScript
- Homepage:
- Size: 89.8 KB
- Stars: 8
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# @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]
[][codacy-url]
[][codacy-url] [](https://stakes.social/0x14308514785B216904a41aB817282d25425Cce39)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)
```### tinyhttp
```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