[node.js] How to validate URLs

const request = require('request');

const options = {
    uri: "https://apost.dev/" // Validate URL
};

request.get(options, function (error, response, body) {
    if(!error && response.statusCode == 200){
        console.log('URI is alive!')
    }else{
        if(response.statusCode == 404)
            console.log('Page not found!')
        else
            console.log('Validate error: ' + response.statusCode);
    }
});

Status code is

  • Informational responses (100 – 199)
  • Successful responses (200 – 299)
  • Redirection messages (300 – 399)
  • Client error responses (400 – 499)
  • Server error responses (500 – 599)