express-robots-txt is an Express.js middleware designed to either serve a static `robots.txt` file or dynamically generate one based on a JavaScript object or array configuration. The package is currently at version 1.0.0, with its last known publication approximately four years ago, indicating a stable but less actively developed state, likely in maintenance mode. It provides a straightforward API to define standard `robots.txt` directives such as `User-agent`, `Disallow`, `Allow`, `Crawl-delay`, `Sitemap` (supporting multiple entries), and `Host`. This flexibility allows developers to easily control how web crawlers interact with their Express applications, preventing unwanted indexing or specifying crawl behaviors, without needing to manage a static file manually for complex scenarios.
npm install express-robots-txtVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to set up `express-robots-txt` middleware to dynamically generate a `robots.txt` file with common directives or serve a static file.
Upgrade to a recent Node.js version (v12.17.0+ for stable ESM support) or use CommonJS `require()` syntax if ESM issues persist.
Use alternative methods for specifying canonical URLs, such as `<link rel="canonical" href="...">` in HTML headers, in addition to or instead of the `Host` directive.
Ensure `app.use(robots(...))` is called with either a file path string or a configuration object/array, e.g., `app.use(robots({ UserAgent: '*', Disallow: '/' }))`.Verify that the object structure follows the documented `robots.txt` directives (e.g., `UserAgent`, `Disallow`). If using a file, ensure the path is correct and the file is readable by the Node.js process.