Detect robots in koa
Note: This post is over 10 years old. The information may be outdated.
Koa detect robots. Fast Middleware detect bot crawler for Koa.
Note (2025): This guide covers the
koa-isbotmiddleware for Koa v1 and v2. The plugin approach is still valid for Koa applications. For modern alternatives, consider checking the User-Agent header directly using libraries likeua-parser-jsor checking if newer bot detection packages are actively maintained.
Installation
npm install koa-isbot --save
Usage
const Koa = require('koa');
const isBot = require('koa-isbot');
const app = new Koa();
app.use(isBot());
app.use(function* (next) {
console.log('isBot? ', this.state.isBot);
// null or 'googlebot', 'bingbot', ...
});
app.listen(3000);
Update for Koa2
const Koa = require('koa');
const isBot = require('koa-isbot');
const app = new Koa();
app.use(isBot());
app.use(async (ctx, next) => {
console.log('isBot? ', ctx.isBot);
// null or 'googlebot', 'bingbot', ...
});
app.listen(3000);
Support list
- Google bot - googlebot
- Baidu - baiduspider
- Guruji - gurujibot
- Yandex - yandexbot
- Slurp- slurp
- MSN - msnbot
- Bing - bingbot
- Facebook - facebookexternalhit
- Linkedin - linkedinbot
- Twitter - twitterbot
- Slack - slackbot
- Telegram - telegrambot
- Apple - applebot
- Pingdom - pingdom
- tumblr - tumblr
Source code
How to contribute
- Fork the project on Github (https://github.com/duyet/koa-isbot/fork)
- Create a topic branch for your changes
- Ensure that you provide documentation and test coverage for your changes (patches won’t be accepted without)
- Create a pull request on Github (these are also a great place to start a conversation around a patch as early as possible)