sitemap-xml

Create a sitemap.xml file by streaming URLs

sitemap.xml

Stream URLs to the sitemap.

var sitemap = require('sitemap-xml');
 
// Raw node 
var http = require('http');
http.createServer(function (requestresponse) {
    res.writeHead(200, {'Content-Type': 'application/xml'});
    var stream = sitemap();
    stream.pipe(response);
    stream.write({ loc: 'http://example.com/', lastmod: '2013-04-21' });
    stream.write({ loc: 'http://example.com/page-1', priority: '0.9' });
    stream.end();
})
 
// Express 
app.get('/sitemap.xml', function(requestresponsenext) {
    var stream = sitemap();
    stream.pipe(response);
    stream.write({ loc: 'http://example.com/', lastmod: '2013-04-21' });
    stream.write({ loc: 'http://example.com/page-1', priority: '0.9' });
    stream.end();
});