The simple package API to check the health of your site.
- HTTP status code check.
- Ignore HTTP codes for filtering results.
- Search regex in your HTML results (Did you miss a
<?php
in your code?). - Full redirect path, specifing code and URL where is redirecting through.
- AMP Audit validation.
- W3C Audit validation.
- Set all the URLs you want to add, set URLs from a sitemap.xml
- Mocking userAgent if you have a mobile version working in your SSR.
- Simple API and chaining methods.
- Full report.
NodeJS > 10 LTS
npm install simple-website-audit
const simpleWebsiteAudit = require("simple-website-audit");
const auditInstance = simpleWebsiteAudit();
auditInstance
.setUrls(["https://www.google.com"])
.make()
.then(report => console.log(report))
.catch(error => console.error(error));
audits
: Specify all the audit instances that will execute:redirect
(boolean, default false): This audit will include in the report all the redirect path that a URL made, i.e. if the URL has a redirect 301 or 302 the redirect path will show you which code was used.regex
(Array<string | RegExp>, default []): This audit will look for all the coincidences in the HTML code for all the values in the array. If it found a coincidence, it will show you the code fragment in that coincidende.w3c
(boolean, default false): This audit will validate your HTML code with the W3C validator, it will show you all the errors and warnings from your code.amp
(boolean, default false): This will run the AMP validation for your HTML code, it will show you all the errors found.
configuration
: Here are some values to use in the audits or in the HTTP request:offsetRegex
(number, default 200): If you are using theregex
audit, this configuration specifies how many characters from the code will be used to show you the fragment, i.e. if you set to 100, once the regex coincidence is found, it will show you a fragment from the 100 chars before the coincidence to the 100 chars after the coincidence.maxTime
(number, default 5000): Miliseconds that the HTTP request will wait for a response before drop it.maxRedirects
(number, default 5): Number of redirects that the HTTP request will consider before it will treat as a infinite server redirect error.resolveWithFullResponse
(number, default true): This is used by the request to build the redirect path.followAllRedirects
(number, default true): This is also used by the request to build the redirect path.ignoreHttpCodes
(Array, default []): You can specify in this configuration which HTTP codes the audit will ignore, the custom audits will not run on these URLs and they will not be included in the report.sitemapUrl
(string, default ""): Specifies the URL of the sitemap the thesetUrlsFromSitemap
method will use to look for URLs.userAgent
(string, default ""): Specifies the userAgent that the request will use in its headers, you can also set this value withsetUserAgent
method, this is useful if you render a different HTML code for a mobile userAgent.
urls
: This is the store for the urls that the instance will use for the audit.report
: This is the store for the report that is generated by themake
method.
Set the audits that the instance will execute. The params will merge with the current audits configuration. Returns the auditInstance
instance.setAudits({
amp: true,
w3c: true,
regex: ["<?php"],
redirect: false
});
Set the urls that the instance will look for. The params will replace with the current urls in the instance. If you set a URL that doesn't specify http or https it will be transformed to https. Returns the auditInstance
// It can be a string
instance.setUrls("https://www.google.com");
// Or ot can be an array
instance.setUrls(["https://www.google.com", "https://www.npmjs.com"]);
// If you don't specify http or https in the URL it will be transformed to https
instance.setUrls("www.google.com"); // Will look for http://www.google.com
Same as setUrls
but this will add the URLs to the instance instead of replace it. Returns the auditInstance
// Set URLs
instance.setUrls("https://www.google.com");
// Add some more to audit
instance.addUrls(["https://www.microsoft.com", "https://www.npmjs.com"]);
Sets the userAgent to use in all the requests of the instance. Returns the auditInstance
// Make the requests as an iPhone
instance.setUserAgent(
"Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1"
);
Sets the configuration of the instance. The params will merge with the current configuration. Returns the auditInstance
instance.setConfiguration({
sitemapUrl: "https://mysite.com/sitemap.xml",
maxRedirects: 3
});
Sets the URLs from the sitemap specified in the configuration, the URLs will replace the current URLs in the instance. This method is async and return the auditInstance
// Inside an async function
await instance.setUrlsFromSitemap();
Execute the audit, this method returns the audit report and also stores that result inside the auditInstance.
const report = await instance.make();
You can also use it as a chainable API
const report = await instance
.setUrls("https://www.mysite.com")
.setAudits({ redirect: true, w3c: true })
.make();
npm test
Contributions are welcome, please free to send a PR or open new issues. You can also contact me at @mikz439