Reputation: 414
We have a job portal website built with MEAN Stack with over 100,000 active jobs and 1,000 active company profile pages.
This data is completely dynamic. Every day tens of job postings and companies are registered.
The problem is that we should keep the sitemap.xml
file(s) always updated with the latest active links.
Does anybody know the best practice to keep the sitemap.xml
always updated in such a dynamic website?
Upvotes: 1
Views: 373
Reputation: 2131
In your express app you can add a sitemap.xml route like so
const xml = require('xml');
... // other routes
app.get('/sitemap.xml', function (req, res) {
// get routes from database or others
response.set('Content-Type', 'text/xml');
response.send(xml(jobs));
})
Your jobs
could contain last edited date and the url to your jobs so it could be very accurate.
Or there are packages like express-sitemap-xml you can use that uses a great example to get routes from a database and generates a sitemap.xml
const express = require('express')
const expressSitemapXml = require('express-sitemap-xml')
const app = express()
app.use(expressSitemapXml(getUrls, 'https://bitmidi.com'))
async function getUrls () {
return await getUrlsFromDatabase() // this function would be to get your database jobs into an object
}
Upvotes: 1