Check wether or not a link is broken.
$ npm install broken-link --save
var brokenLink = require('broken-link');
brokenLink('http://non-existing-domain-name.com')
.then(function(answer) {
console.log('link is%s broken', answer ? '' : ' not'); // link is broken
});
To determine if a link is broken, some of the following must be true:
- Request fails with an error.
- Request response status code is
404
. - Response identified a redirect.
- Page URL matches
options.match404Page
.
Note that this is the default behavior but you can fully customize it.
Return: promise
Required
Type: string
URL to test against.
Type: object
Available options.
Type: boolean
Default: false
Wether or not to allow redirects.
Type: boolean
Default: false
Wether or not 404 pages are allowed. To tell if it's a 404 page, it will test again the request URL. See options.match404Page
.
Type: boolean
Default: false
This is an alias to both options.allowRedirects
and options.allow404Pages
. For more information about soft 404's, click here.
Type: array
Defaults: an empty array
List of error codes that should be ignored.
Type: array
Defaults: an empty array
List of status codes that should be ignored.
Type: regexp
Default: /404|erro|page/i
Pattern that checks if a URL can be considered a 404 page.
MIT © Rafael Rinaldi