How to Make Your Own XML Site Map Generator Using Express JS......

HELLO FRIENDS......This is The Post About How to Make Your Own XML Site Map Generator Using  Express and sitemap-generator Package.. . IF You Don't Know How to Make Your Own XML Site Map Generator Using  Express and sitemap-generator Package. Then This  Post  is For You . So Check Out Full Post......


TAGS :


HTML , EXPRESS JS ,  SITEMAP-GENERATOR, MAKE YOUR OWN SITEMAP GENERATOR , SITE MAP GENERATOR , xml site generator , xml sitemap kya hai



Page Content : 


Some Basic Defination Of Site Map for UnderStand What is XML Site Map
 
Which NPM Package is Required To Install
 
Express JS With Example 
 
HTML Code With Example
 
Testing Of XML SITE MAP GENERATOR



Do You Know That , Google and Other Search Engines How to Find Your Website .There is One File Its Called XML Site map . By Using This XML Site Map Google Bots or Other Search Engines Bots Detect Your Hole Website.XML Site Map is Very Important Part for SEO.  



Make Your Own XML Site Map Generator By Using Exprees JS

For That First Make One Folder sitemap generator and Go this Folder Terminal Part and Run This Command : npm init . After That package.json  File Will Automatically Add in sitemapgenerator Folder Now Install this Package.



This NPM Package is Required to Install in Your Main Folder to Make Site Map Generator Using  Express and sitemap-generator..


1) Express  - https://www.npmjs.com/package/express (npm install express)


2) sitemap - generator - https://www.npmjs.com/package/sitemap-generator (npm install sitemap-generator)






After Installing This Package of Your Main Project Folder We Need To Make One  app.js File Now Write This Basic Command Of Express....






const express = require("express"); const app = express(); const path = require("path"); const SitemapGenerator = require('sitemap-generator'); const mainpath = path.join(__dirname,"../CONVERTER"); app.use(express.static(mainpath)); app.get("/",(req,res)=>{ res.send(index); }); app.listen(8000,()=>{ console.log("server Started Successfully"); });










Now Add Sitemap Generator Command To index.js File






app.get("/getsitemap",async(req,res)=>{ const url = await req.query.url; if(url=="") { res.send("Please Enter Valid Details") } const outputfile = await "sitemap.xml"; const generator = await SitemapGenerator(url, { stripQuerystring: false }); generator.on('done', () => { res.download(outputfile); }); generator.start(); })



Your Hole index.js File is : 





const express = require("express"); const app = express(); const path = require("path"); const SitemapGenerator = require('sitemap-generator'); const mainpath = path.join(__dirname,"../CONVERTER"); app.use(express.static(mainpath)); app.get("/",(req,res)=>{ res.send(index); }) app.get("/getsitemap",async(req,res)=>{ const url = await req.query.url; if(url=="") { res.send("Please Enter Valid Details") } const outputfile = await "sitemap.xml"; const generator = await SitemapGenerator(url, { stripQuerystring: false }); generator.on('done', () => { res.download(outputfile); }); generator.start(); })








After Making index.js File Make One HTML File To Get Input Domain name or Domain Link From Any User So index.html File is ....






<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Site Map Generator</title> <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.2/css/all.css"> <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap"> <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet"> <link href="https://cdnjs.cloudflare.com/ajax/libs/mdbootstrap/4.19.1/css/mdb.min.css" rel="stylesheet"> </head> <body> <div class="container"> <h3 style="margin-top:40px;">Site Map Generator</h3> <form action="/getsitemap" method="GET" style="margin-top:50px"> <div class="md-form form-lg"> <input type="text" id="input" class="form-control form-control-lg" name="url" > <label for="url">domain.com or www.domain.com</label> </div> <button type="submit" value="submit" class="btn btn-success">Download</button> </form> </div> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.4/umd/popper.min.js"></script> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/js/bootstrap.min.js"></script> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mdbootstrap/4.19.1/js/mdb.min.js"></script> </body> </html>








       

       

After Making This Two Files Start Server Using nodemon index.js or Else node index.js . Now you Show This Type of Front end :





Now Put Any Domain Name or Domain Link

And Try It by

Yourself

If Site is Very Huge

then It Take Some Time

.......


Conclusion :


This is All About How to Make Your Own XML Site Map Generator Using  Express JS.BY using This  Method You Can Make Your Own XML Site Map Generator. If You Like This Article Content Then Like and Share it With Your Friends and Family.



I HOPE THAT THIS POST IS HELPFUL FOR YOU.


THANKYOU FOR READING.



About Author : 

Hello friends, I am Abhi Patel author & founder of Technovichar.com. I am a student of IT engineering. I like to research and write about new things even if it is from any field. You will continue to support us in this way, we will keep on bringing such interesting information for you.

Post a Comment

0 Comments