New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

botpolice

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

botpolice

Detects automated or crawler requests based on User-Agent heuristics.

latest
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

botpolice

Canonical URL:
https://alexstevovich.com/a/botpolice-nodejs

Software URL:
https://midnightcitylights.com/software/botpolice-nodejs

botpolice is a simple utility for detecting automated or crawler requests based on the User-Agent heuristics. It checks if the User-Agent string matches common bot names like "bot", "spider", "crawler", and others.

Installation

npm install botpolice

Example

import express from 'express';
import botpolice from 'botpolice';

const app = express();

// Use botpolice to block requests from bots
app.use((req, res, next) => {
    if (botpolice(req)) {
        res.status(403).send('Bot detected!');
    } else {
        next();
    }
});

app.get('/', (req, res) => {
    res.send('Hello, world!');
});

app.listen(3000, () => {
    console.log('Server running on http://localhost:3000');
});

Function

botpolice(req)

  • req: The request object.
  • Returns: true if the request is from a bot, false otherwise.

The function checks the User-Agent header in the request and matches it against common bot patterns (e.g., "bot", "spider", "crawler", etc.).

License

Licensed under the MIT License.

Keywords

bot

FAQs

Package last updated on 12 Nov 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts