Environment: Node.js, Express, node-fetch
Question: I'm attempting to use node-fetch to determine if a website is active. This works fine for https. However when I test http it always comes back as ok = true, status = 200 & statusText = OK. Even when I use random characters and letters for the url such as qwerweqr12341243124.net it always comes back the same way. Is there a better way to use fetch to determine if the http version is active? Is a different tool required?
Example: The simplified example below checks to see if there is an active http and https version of a website.
const fetch = require('node-fetch');
function checkIfWebsiteExists(website) {
let httpVersion = `http://${ website }`;
let httpsVersion = `https://${ website }`;
fetch(httpVersion)
.then(function(response) {
console.log('http ok', response.ok);
console.log('http status', response.status);
console.log('http statusText', response.statusText);
})
.catch(function(err) {
console.log(err);
});
fetch(httpsVersion)
.then(function(response) {
console.log('https ok', response.ok);
console.log('https status', response.status);
console.log('https statusText', response.statusText);
})
.catch(function(err) {
console.log(err);
});
}