//This code is attached. Only the broken links on the provided url are displayed to us; I required it for the entire website. I’m getting the broken links on the specified single page. Is there a way to find the broken links on the sitemap.xml file using node.js?
const express = require('express')
const {exec} = require('child_process')
const app = express ()
const bodyparser = require('body-parser')
app.use(bodyparser.json())
app.use(bodyparser.urlencoded({extended:false}))
app.set('view engine','ejs')
app.get('/',(req,res)=>{
res.render('brokenlinkchecker',{title:'broken link checker',info:''})
})
app.post('/brokenlinkchecker',(req,res)=>{
exec('brkn '+ req.body.url + ' --verbose',(err,stdout,stderr) => {
if(err){
res.send(err)
}
console.log(stdout)
res.render('brokenlinkchecker',{title:'broken link checker',info:stdout})
})
})
app.listen(5000)
//Front End Part
<!DOCTYPE html>
<html>
<head>
<title>Broken Link Checker</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<h1 class="text-center" style="color: #fe620a;">
Broken Link checker
</h1>
<br>
<form action="/brokenlinkchecker" method="post">
<div class="form-group">
<label for="url">Website URL:</label>
<input type="text" name="url" required placeholder="Enter URL" class="form-control">
</div>
<div class="form-group">
<button class="btn btn-danger btn-block" style="background-color: #fe620a;">
Get Broken Links
</button>
</div>
<div class="form-group">
<label for="links">Broken Links:</label>
<textarea readonly class="form-control" placeholder="broken links" cols="30" rows="10"> <%= info %></textarea>
</div>
</form>
</div>
</body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
</html>