How to create sitemap.xml with Sailsjs

I am trying to figure out how to have a sitemap with sails.js

I tried using sitemap-express, but it seems to be for expressing routing.


source to share

1 answer

Although this question is quite old, but I would like to post a solution here for seekers, for example I landed here.

First you need to install sitemap-generator

Let's say I have a route 'get /sitemap' : 'SitemapController.build_sitemap',


    sitemap: function(req, res) {
       var fs = require('fs');
       var SitemapGenerator = require('sitemap-generator');
       var generator = new SitemapGenerator('');
       generator.on('done', function (sitemap) {

           fs.writeFile("./assets/sitemap.xml", sitemap, function(err){
               if(err) {
                   return res.negotiate(err);
               console.log("The file was saved!");


At this point, a sitemap.xml file will be created in the directory. / assets (you can put it wherever you want, its choice / decision is made)

NOW , that you already have the .xml in your project, all that remains is to return / map the sitemap.xml file to the GET route.




All Articles