🤖 Bot detector for Node.js
Go to file
v1rtl 98995760d3
Merge pull request #2 from omrilotan/isbot_upgrade
Upgrade isbot major version
2024-01-04 13:09:07 +02:00
.github more badges 2021-06-23 18:30:39 +03:00
src Upgrade isbot major version 2024-01-03 16:27:28 +00:00
tests bump deps and fix package.json 2023-05-27 22:16:28 +03:00
.eslintrc move to separate repo 2021-06-23 18:10:37 +03:00
.gitignore move to separate repo 2021-06-23 18:10:37 +03:00
.prettierrc move to separate repo 2021-06-23 18:10:37 +03:00
LICENSE move to separate repo 2021-06-23 18:10:37 +03:00
README.md Update README.md 2023-05-27 14:35:45 -04:00
package.json Upgrade isbot major version 2024-01-03 16:27:28 +00:00
pnpm-lock.yaml Upgrade isbot major version 2024-01-03 16:27:28 +00:00
rollup.config.js fix rollup config 2023-05-27 22:17:19 +03:00
tsconfig.json fix type errors 2021-06-23 18:24:41 +03:00

README.md

@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)