{"id":17399251,"url":"https://github.com/feross/express-sitemap-xml","last_synced_at":"2025-08-01T06:33:37.370Z","repository":{"id":33116069,"uuid":"140989101","full_name":"feross/express-sitemap-xml","owner":"feross","description":"Serve sitemap.xml from a list of URLs in Express","archived":false,"fork":false,"pushed_at":"2024-04-19T22:52:16.000Z","size":201,"stargazers_count":67,"open_issues_count":1,"forks_count":11,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-13T02:56:35.993Z","etag":null,"topics":["express","javascript","middleware","nodejs","sitemap","sitemap-generator","sitemap-xml"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/feross.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-07-15T01:13:40.000Z","updated_at":"2024-04-19T22:51:28.000Z","dependencies_parsed_at":"2024-06-18T16:56:49.854Z","dependency_job_id":"96d3d65d-eee3-464f-ac6a-e97ff1088b6b","html_url":"https://github.com/feross/express-sitemap-xml","commit_stats":{"total_commits":26,"total_committers":4,"mean_commits":6.5,"dds":0.3076923076923077,"last_synced_commit":"ae674928b355acefd3db46c5f6bf4429bad52a2c"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feross%2Fexpress-sitemap-xml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feross%2Fexpress-sitemap-xml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feross%2Fexpress-sitemap-xml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feross%2Fexpress-sitemap-xml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/feross","download_url":"https://codeload.github.com/feross/express-sitemap-xml/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248657872,"owners_count":21140844,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["express","javascript","middleware","nodejs","sitemap","sitemap-generator","sitemap-xml"],"created_at":"2024-10-16T15:14:08.875Z","updated_at":"2025-04-13T02:57:21.781Z","avatar_url":"https://github.com/feross.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# express-sitemap-xml [![travis][travis-image]][travis-url] [![npm][npm-image]][npm-url] [![downloads][downloads-image]][downloads-url] [![javascript style guide][standard-image]][standard-url]\n\n[travis-image]: https://img.shields.io/travis/feross/express-sitemap-xml/master.svg\n[travis-url]: https://travis-ci.org/feross/express-sitemap-xml\n[npm-image]: https://img.shields.io/npm/v/express-sitemap-xml.svg\n[npm-url]: https://npmjs.org/package/express-sitemap-xml\n[downloads-image]: https://img.shields.io/npm/dm/express-sitemap-xml.svg\n[downloads-url]: https://npmjs.org/package/express-sitemap-xml\n[standard-image]: https://img.shields.io/badge/code_style-standard-brightgreen.svg\n[standard-url]: https://standardjs.com\n\n### Express middleware to serve [`sitemap.xml`](https://en.wikipedia.org/wiki/Sitemaps) from a list of URLs\n\nCreate an Express middleware that serves `sitemap.xml` from a list of URLs.\n\nThis package automatically handles sitemaps with more than 50,000 URLs. In these\ncases, multiple sitemap files will be generated along with a \"sitemap index\" to\ncomply with the [sitemap spec](https://www.sitemaps.org/protocol.html) and\nrequirements from search engines like Google.\n\nIf only one sitemap file is needed (i.e. there are less than 50,000 URLs) then\nit is served directly at `/sitemap.xml`. Otherwise, a sitemap index is served at\n`/sitemap.xml` and sitemaps at `/sitemap-0.xml`, `/sitemap-1.xml`, etc.\n\n## Install\n\n```\nnpm install express-sitemap-xml\n```\n\n## Demo\n\nYou can see this package in action on [BitMidi](https://bitmidi.com), a site for\nlistening to your favorite MIDI files.\n\n## Usage (with Express)\n\nThe easiest way to use this package is with the Express middleware.\n\n```js\nconst express = require('express')\nconst expressSitemapXml = require('express-sitemap-xml')\n\nconst app = express()\n\napp.use(expressSitemapXml(getUrls, 'https://bitmidi.com'))\n\nasync function getUrls () {\n  return await getUrlsFromDatabase()\n}\n```\n\nRemember to add a `Sitemap` line to `robots.txt` like this:\n\n```\nSitemap: https://bitmidi.com/sitemap.xml\n```\n\n## Usage (without Express)\n\nThe package can also be used without the Express middleware.\n\n```js\nconst { buildSitemaps } = require('express-sitemap-xml')\n\nasync function run () {\n  const urls = ['/1', '/2', '/3']\n  const sitemaps = await buildSitemaps(urls, 'https://bitmidi.com')\n\n  console.log(Object.keys(sitemaps))\n  // ['/sitemap.xml']\n\n  console.log(sitemaps['/sitemap.xml'])\n  // `\u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n  //  \u003curlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"\u003e\n  //    \u003curl\u003e\n  //      \u003cloc\u003ehttps://bitmidi.com/1\u003c/loc\u003e\n  //      \u003clastmod\u003e${getTodayStr()}\u003c/lastmod\u003e\n  //    \u003c/url\u003e\n  //    \u003curl\u003e\n  //      \u003cloc\u003ehttps://bitmidi.com/2\u003c/loc\u003e\n  //      \u003clastmod\u003e${getTodayStr()}\u003c/lastmod\u003e\n  //    \u003c/url\u003e\n  //    \u003curl\u003e\n  //      \u003cloc\u003ehttps://bitmidi.com/3\u003c/loc\u003e\n  //      \u003clastmod\u003e${getTodayStr()}\u003c/lastmod\u003e\n  //    \u003c/url\u003e\n  //  \u003c/urlset\u003e`\n})\n```\n\nRemember to add a `Sitemap` line to `robots.txt` like this:\n\n```\nSitemap: https://bitmidi.com/sitemap.xml\n```\n\n## API\n\n### `middleware = expressSitemapXml(getUrls, base)`\n\nCreate a `sitemap.xml` middleware. Both arguments are required.\n\nThe `getUrls` argument specifies an async function that resolves to an array of\nURLs to be included in the sitemap. Each URL in the array can either be an\nabsolute or relative URL string like `'/1'`, or an object specifying additional\noptions about the URL:\n\n```js\n{\n  url: '/1',\n  lastMod: new Date('2000-02-02'), // optional (specify `true` for today's date)\n  changeFreq: 'weekly' // optional\n}\n```\n\nFor more information about these options, see the [sitemap spec](https://www.sitemaps.org/protocol.html). Note that the `priority` option is not supported because [Google ignores it](https://twitter.com/methode/status/846796737750712320).\n\nThe `getUrls` function is called at most once per 24 hours. The resulting\nsitemap(s) are cached to make repeated HTTP requests faster.\n\nThe `base` argument specifies the base URL to be used in case any URLs are\nspecified as relative URLs. The argument is also used if a sitemap index needs\nto be generated and sitemap locations need to be specified, e.g.\n`${base}/sitemap-0.xml` becomes `https://bitmidi.com/sitemap-0.xml`.\n\n### `sitemaps = expressSitemapXml.buildSitemaps(urls, base)`\n\nCreate an object where the keys are sitemap URLs to be served by the server and\nthe values are strings of sitemap XML content. (This function does no caching.)\n\nThe `urls` argument is an array of URLs to be included in the sitemap. Each URL\nin the array can either be an absolute or relative URL string like `'/1'`, or an\nobject specifying additional options about the URL. See above for more info\nabout the options.\n\nThe `base` argument is the same as above.\n\nThe return value is an object that looks like this:\n\n```js\n{\n  '/sitemap.xml': '\u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e...'\n}\n```\n\nOr if multiple sitemaps are needed, then the return object looks like this:\n\n```js\n{\n  '/sitemap.xml': '\u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e...',\n  '/sitemap-0.xml': '\u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e...',\n  '/sitemap-1.xml': '\u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e...'\n}\n```\n\n## License\n\nMIT. Copyright (c) [Feross Aboukhadijeh](https://feross.org).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffeross%2Fexpress-sitemap-xml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffeross%2Fexpress-sitemap-xml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffeross%2Fexpress-sitemap-xml/lists"}