Node.js Express Domain or Website XML Sitemap Generator Online Tool Website Deployed on Website + Source Code 2020

You are currently viewing Node.js Express Domain or Website XML Sitemap Generator Online Tool Website Deployed on Website + Source Code 2020



Welcome folks today in this tutorial we will be building a online tool web app which will be a simple XML Sitemap Generator for the Website or Domain. All the source code of the application is shown below


Live Demo



You can see the live demo of the online tool here



Get Started



In order to get started we need to install these dependencies


npm init -y


npm i express ejs sitemap-generator


So install all these dependencies inside your node.js project and open it inside a text editor


So now we need to make a simple index.js file for the application




const express = require("express");

const SitemapGenerator = require('sitemap-generator');

const app = express()

const bodyparser = require('body-parser')


app.set('view engine','ejs')


app.get('/xmlsitemapgenerator',(req,res) => {

  res.render('xmlsitemapgenerator',{title:'Generate XML Sitemap for Domain Online - XML Sitemap Generator Online -'})
  })'/xmlsitemapgenerator',(req,res) => {
  var url = req.body.url
  var outputfile = + "output.xml"
  const generator = SitemapGenerator(url, {
    stripQuerystring: false,
  // register event listeners
  generator.on('done', () => {,(err) => {
  fs.unlinkSync(outputfile)"unable to download the sitemap file")
  // start the crawler





Creating EJS Templates



Now inside your root directory create the views folder and create a simple view called xmlsitemapgenerator.ejs and copy paste the below code






<div class="container">
          <h1 class="text-center">
              XML Sitemap Generator
          <form action="/xmlsitemapgenerator" method="post">
            <div class="form-group">
                <label for="url">Website URL:</label>
                <input class="form-control" type="text" placeholder="" name="url" id="" required>
            <div class="form-group">
                <button class="btn btn-block btn-danger">
                    Download Sitemap File










Create Sitemaps on Command Line



You can also create xml sitemaps on the command line also by installing this dependency globally on your machine


npm i -g sitemap-generator-cli


After installing it you just need to execute the command on command line






And now to get sitemap of you need to execute the command like




This will create the xml sitemap of this domain in the same folder like this as shown below







Leave a Reply