This library helps in validating whether a url exists or not. It verifies url pattern and whether the url is up and running.
Please consider donating, if you like my work
npm install ak-url-validate
var auv = require('ak-url-validate');
const url = 'http://github.com/arshadkazmi42';
const response = await auv.isValidUrl(url);
if (response.isValid) {
// Do something if the url is valid
} else {
// Do something if url is invalid
}
isValid function returns status code whatever is returned from the url response. Some of the status codes are mentioned below
- SUCCESS: This code is returned when the url is up and running.
{
code: "SUCCESS",
isValid: true
}
- 404: This code is returned when the url is not found.
{
code: 404,
isValid: false,
message: "Not Found"
}
- ETIMEDOUT: This code is returned when the url is not responsding and get timed out.
{
isValid: false,
code: "ETIMEDOUT",
message: "Invalid Url"
}
- INVALID: This is an exception code, if the url does not return any status code, this code is returned in the response
{
isValid: false,
code: "INVALID",
message: "Invalid Url"
}
Read the contributing guidelines here