Wondering what’s next for npm?Check out our public roadmap! »

    @tinyhttp/bot-detector
    TypeScript icon, indicating that this package has built-in type declarations

    1.3.8 • Public • Published

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

    Install

    npm i @tinyhttp/bot-detector

    DownloadsWeekly Downloads

    124

    Version

    1.3.8

    License

    MIT

    Unpacked Size

    5.91 kB

    Total Files

    6

    Last publish

    Collaborators

    • avatar