npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mr.robot

v1.0.0

Published

For setting robots meta tags and X-Robots-Tag headers

Downloads

5

Readme

alt tag

Mr. Robot helps you set robots meta tags and X-Robots-Tag headers as per Robots meta tag and X-Robots-Tag HTTP header specifications.

X-Robots-Tag HTTP Response Header

Set an X-Robots-Tag response header for all crawlers

var mrRobot = require('mr.robot')

app.get('/example', function(req, res) {
    mrRobot(res).noIndex().noFollow()
})

Results in the following response header

x-robots-tag: noindex, nofollow

Set an X-Robots-Tag response header for specific crawlers

var mrRobot = require('mr.robot')

app.get('/example', function(req, res) {
    mrRobot(res).noIndex('googlebot').noFollow('googlebot')
})

Results in the following response header

x-robots-tag: googlebot: noindex, nofollow

Due to https://github.com/nodejs/node/issues/3591 it is not currently possible to set directives for multiple user agents using the X-Robots-Tag response header. For the moment you can only do this with meta robots tags.

Meta Robots Tag

Rendering a robots meta tag for all crawlers (with Moustache)

var mrRobot = require('mr.robot')

app.get('/example', function(req, res) {
    mrRobot(res)
        .noIndex()
        .noFollow()
    res.render('example', { robots: mrRobot(res).meta })
})

example.tmpl

{{#robots}}
    <meta name="{{name}}" content="{{content}}" />
{{/robots}}

Results in the following output

   <meta name="robots" content="noindex, nofollow" />

Rendering a robots meta tag for specific crawlers (with Moustache)

app.get('/example', function(req, res) {
    mrRobot(res)
        .noIndex('googlebot')
        .noFollow('otherbot')
        .all('none')
    res.render('example', { robots: mrRobot(res).meta })
})

example.tmpl

{{#robots}}
    <meta name="{{name}}" content="{{content}}" />
{{/robots}}

Results in the following output

   <meta name="googlebot" content="noindex" />
   <meta name="otherbot" content="nofollow" />
   <meta name="robots" content="none" />

Supported Directives

| Directive | Alias | |-------------------|------------------------| | all | | | noindex | noIndex | | nofollow | noFollow | | none | | | noarchive | noArchive | | nosnipper | noSnipper | | noodp | noOpenDirectoryProject | | notranslate | noTranslate | | noimageindex | noImageIndex | | unavailable_after | unavailableAfter |

All methods accept an optional user agent name (e.g. 'googlebot') as their first parameter. unavailable_after/unavailableAfter requires an instance of Date, e.g.

mrRobot(res).unavailableAfter(new Date())
// or
mrRobot(res).unavailableAfter('googlebot', new Date())

Options

You can customise behaviour the first time you intialise mr.robot through the options parameter

mrRobot(res, options)

logger

Allows you to specify your own logger (otherwise mr.robot will use console), e.g.

var mrRobot = require('mr.robot')

app.get('/example', function(req, res) {
    mrRobot(res, { logger: myLogger }).noIndex('googlebot').noFollow('googlebot')
})

autoWrite

Controls whether mr.robot automatically writes headers before response.end(). If you disable this you must explicitly call write headers for them to be output, e.g.

var mrRobot = require('mr.robot')

app.get('/example', function(req, res) {
    mrRobot(res, { autoWrite: false }).noIndex('googlebot').noFollow('googlebot').writeHeader()
})