The `robots.txt` package provides simple Connect/Express middleware to serve a static `robots.txt` file from the filesystem. Currently at version 1.1.0, this package was last published over a decade ago, indicating it is no longer actively maintained. Its core functionality involves a single synchronous read of the `robots.txt` file upon application startup, with subsequent requests served from memory. It automatically sets appropriate cache headers. Unlike many other `robots.txt` related packages on npm, this library is strictly for serving the file content at the `/robots.txt` endpoint, not for parsing or evaluating robots exclusion rules for crawlers. Its simplicity and 'fire-and-forget' setup were its primary differentiators in its active period, but it lacks modern features like asynchronous file handling, ESM support, or TypeScript typings.
npm install robots.txtVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates setting up an Express application to serve a `robots.txt` file using the middleware. It creates a dummy `robots.txt` on the fly and shows how the middleware integrates into an Express app, serving the file at the `/robots.txt` endpoint.
No direct fix within the package. For highly performant applications, consider serving static robots.txt via a web server (e.g., Nginx) or using custom asynchronous middleware.
Consider migrating to a manually served static file using `app.get('/robots.txt', ...)` or a more modern, actively maintained alternative like `express-robots.txt`.If dynamic `robots.txt` generation or parsing is required, use a different library explicitly designed for those purposes.
Create a `d.ts` declaration file (e.g., `declare module 'robots.txt';`) or use a different, actively maintained solution that provides TypeScript support.
Ensure the path passed to `robots()` is an absolute path to a valid `robots.txt` file. Use `path.join(__dirname, 'robots.txt')` for relative paths within your project.
Verify that `robots.txt` is correctly installed and that the path passed to the `robots()` function is a non-empty string and resolves to a readable file.
Ensure `app.use(robots(pathToRobotsTxt))` is placed early in your middleware stack, before any general static file servers or route handlers that might capture `/robots.txt`.