Gathering detailed insights and metrics for @lydell/express-sitemap-xml
Gathering detailed insights and metrics for @lydell/express-sitemap-xml
Gathering detailed insights and metrics for @lydell/express-sitemap-xml
Gathering detailed insights and metrics for @lydell/express-sitemap-xml
Serve sitemap.xml from a list of URLs in Express
npm install @lydell/express-sitemap-xml
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
15 Commits
1 Watchers
2 Branches
1 Contributors
Updated on Mar 18, 2019
Latest Version
1.1.1
Package Id
@lydell/express-sitemap-xml@1.1.1
Unpacked Size
14.14 kB
Size
4.84 kB
File Count
5
NPM Version
6.4.1
Node Version
10.14.2
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
2
3
sitemap.xml
from a list of URLsCreate an Express middleware that serves sitemap.xml
from a list of URLs.
This package automatically handles sitemaps with more than 50,000 URLs. In these cases, multiple sitemap files will be generated along with a "sitemap index" to comply with the sitemap spec and requirements from search engines like Google.
If only one sitemap file is needed (i.e. there are less than 50,000 URLs) then
it is served directly at /sitemap.xml
. Otherwise, a sitemap index is served at
/sitemap.xml
and sitemaps at /sitemap-0.xml
, /sitemap-1.xml
, etc.
npm install @lydell/express-sitemap-xml
You can see this package in action on BitMidi, a site for listening to your favorite MIDI files.
The easiest way to use this package is with the Express middleware.
1const express = require('express') 2const expressSitemapXml = require('@lydell/express-sitemap-xml') 3 4const app = express() 5 6app.use(expressSitemapXml(getUrls, 'https://bitmidi.com')) 7 8async function getUrls () { 9 return await getUrlsFromDatabase() 10}
Remember to add a Sitemap
line to robots.txt
like this:
Sitemap: https://bitmidi.com/sitemap.xml
The package can also be used without the Express middleware.
1const { buildSitemaps } = require('@lydell/express-sitemap-xml') 2 3async function run () { 4 const urls = ['/1', '/2', '/3'] 5 const sitemaps = await buildSitemaps(urls, 'https://bitmidi.com') 6 7 console.log(Object.keys(sitemaps)) 8 // ['/sitemap.xml'] 9 10 console.log(sitemaps['/sitemap.xml']) 11 // `<?xml version="1.0" encoding="utf-8"?> 12 // <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> 13 // <url> 14 // <loc>https://bitmidi.com/1</loc> 15 // <lastmod>${getTodayStr()}</lastmod> 16 // </url> 17 // <url> 18 // <loc>https://bitmidi.com/2</loc> 19 // <lastmod>${getTodayStr()}</lastmod> 20 // </url> 21 // <url> 22 // <loc>https://bitmidi.com/3</loc> 23 // <lastmod>${getTodayStr()}</lastmod> 24 // </url> 25 // </urlset>` 26})
Remember to add a Sitemap
line to robots.txt
like this:
Sitemap: https://bitmidi.com/sitemap.xml
middleware = expressSitemapXml(getUrls, base)
Create a sitemap.xml
middleware. Both arguments are required.
The getUrls
argument specifies an async function that resolves to an array of
URLs to be included in the sitemap. Each URL in the array can either be an
absolute or relative URL string like '/1'
, or an object specifying additional
options about the URL:
1{ 2 url: '/1', 3 lastMod: new Date('2000-02-02'), 4 changeFreq: 'weekly' 5}
For more information about these options, see the sitemap spec. Note that the priority
option is not supported because Google ignores it.
You can also pass each item as an array to create language links.
The getUrls
function is called at most once per 24 hours. The resulting
sitemap(s) are cached to make repeated HTTP requests faster.
The base
argument specifies the base URL to be used in case any URLs are
specified as relative URLs. The argument is also used if a sitemap index needs
to be generated and sitemap locations need to be specified, e.g.
${base}/sitemap-0.xml
becomes https://bitmidi.com/sitemap-0.xml
.
In order to tell Google about localized versions of your page, use arrays of language-url pairs:
1[ 2 { 3 url: '/', 4 lastMod: '2000-01-01', 5 changeFreq: 'daily' 6 }, 7 [ 8 { 9 language: 'en', 10 url: '/english/page.html' 11 }, 12 { 13 language: 'de', 14 url: { 15 url: '/deutsch/page.html', 16 lastMod: new Date('2000-02-02'), 17 changeFreq: 'weekly' 18 } 19 }, 20 { 21 language: 'de-ch', 22 url: { 23 url: '/schweiz-deutsch/page.html', 24 changeFreq: 'daily' 25 } 26 } 27 ] 28]
1<?xml version="1.0" encoding="utf-8"?> 2<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> 3 <url> 4 <loc>https://www.example.com/</loc> 5 <lastmod>2000-01-01</lastmod> 6 <changefreq>daily</changefreq> 7 </url> 8 <url> 9 <loc>https://www.example.com/english/page.html</loc> 10 <lastmod>${getTodayStr()}</lastmod> 11 <xhtml:link rel="alternate" hreflang="en" href="https://www.example.com/english/page.html"/> 12 <xhtml:link rel="alternate" hreflang="de" href="https://www.example.com/deutsch/page.html"/> 13 <xhtml:link rel="alternate" hreflang="de-ch" href="https://www.example.com/schweiz-deutsch/page.html"/> 14 </url> 15 <url> 16 <loc>https://www.example.com/deutsch/page.html</loc> 17 <lastmod>2000-02-02</lastmod> 18 <changefreq>weekly</changefreq> 19 <xhtml:link rel="alternate" hreflang="en" href="https://www.example.com/english/page.html"/> 20 <xhtml:link rel="alternate" hreflang="de" href="https://www.example.com/deutsch/page.html"/> 21 <xhtml:link rel="alternate" hreflang="de-ch" href="https://www.example.com/schweiz-deutsch/page.html"/> 22 </url> 23 <url> 24 <loc>https://www.example.com/schweiz-deutsch/page.html</loc> 25 <lastmod>${getTodayStr()}</lastmod> 26 <changefreq>daily</changefreq> 27 <xhtml:link rel="alternate" hreflang="en" href="https://www.example.com/english/page.html"/> 28 <xhtml:link rel="alternate" hreflang="de" href="https://www.example.com/deutsch/page.html"/> 29 <xhtml:link rel="alternate" hreflang="de-ch" href="https://www.example.com/schweiz-deutsch/page.html"/> 30 </url> 31</urlset>
sitemaps = expressSitemapXml.buildSitemaps(urls, base)
Create an object where the keys are sitemap URLs to be served by the server and the values are strings of sitemap XML content. (This function does no caching.)
The urls
argument is an array of URLs to be included in the sitemap. Each URL
in the array can either be an absolute or relative URL string like '/1'
, or an
object specifying additional options about the URL. See above for more info
about the options.
The base
argument is the same as above.
The return value is an object that looks like this:
1{ 2 '/sitemap.xml': '<?xml version="1.0" encoding="utf-8"?>...' 3}
Or if multiple sitemaps are needed, then the return object looks like this:
1{ 2 '/sitemap.xml': '<?xml version="1.0" encoding="utf-8"?>...', 3 '/sitemap-0.xml': '<?xml version="1.0" encoding="utf-8"?>...', 4 '/sitemap-1.xml': '<?xml version="1.0" encoding="utf-8"?>...' 5}
MIT. Copyright (c) Feross Aboukhadijeh and Simon Lydell.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
no SAST tool detected
Details
Reason
Found 0/15 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More