link-crawler
A simple Node.js package that crawls internal links of a website and generates a sitemap.
Installation
npm install @moataz84/link-crawler
Usage
Importing the Module
const { validateURLInput, crawlURL, generateSitemap } = require("link-crawler")
Functions
validateURLInput(usrInput): async
Asynchronous function that validates user input to determine if it's a valid URL. Returns the full URL with appropriate protocol (HTTP/HTTPS).
validateURLInput("example.com").then(resp => {
console.log(resp)
})
crawlURL(URL): async
Asynchronous function that crawls a URL and returns a list of internal links. Recommended to be used in combination with validateURLInput(URL).
validateURLInput("example.com").then(async resp => {
const links = await crawlURL(resp.URL)
console.log(links)
})
generateSitemap(URL): async
Asynchronous function that generates a sitemap file for the given URL, saves it in the local directory, and returns the file name. Recommended to be used in combination with validateURLInput(URL).
validateURLInput("example.com").then(async resp => {
const sitemap = await generateSitemap(resp.URL)
console.log(sitemap)
})
License
MIT