Create a sitemap.xml with Node.js and EJS

Create a sitemap.xml with Node.js and EJS

A site map (or sitemap) is a list of pages of a web site allowing users and search engines to find the data faster and more efficiently.

router.get('/sitemap.xml', controller.sitemap)
exports.sitemap = (req, res, next) => {
	//Return an XML content type
  	res.set('Content-Type', 'text/xml')

  	//Get and return data to generate the sitemap
    res.render('html/sitemap', {
        //whatever data you need to show in the sitemap
        article: []
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="" xmlns:xsi=""

    <% articles.forEach(article=>{ %>
            <lastmod>< RegExp('/', 'g'), "-")%></lastmod>
    <% }) %>