An image of a code editor displaying HTML code

Yet Another Link Checker Utility

Print Friendly and PDF

Posted: Friday, November 15, 2024 at 06:03 PM | Categories: Web Development

I played around this week with validating all of the links on this site and trying some tools. As part of my research I found an article called Using Node.js to Check for Broken Links that showed how to use the npm package linkinator to build a command-line tool for validating links on a URI.

I quickly built a command-line tool using information from the article and the linkinator package's documentation. Before long I had a full fledged link checker that met my specific needs. I called my link checker link-checker but since there is already a package with that name on npm, I had to add my npm username to the package name: @johnwargo/link-checker.

Validating Links On This Site

In my next post, I spend more time explaining how I used the two utilities to fix a lot of the links on this site.

The utility doesn't require any command-line parameters (which I like because I always forget them, especially for my own command-line tools) but does support a couple of them. What I like best of this utility is that it allows me to save the results to a file, enabling me to open it later in an editor and double-check the links the utility reported as broken.

The reason for this is that many sites (like the Adafruit Forums) have a human checker in front of access, so for that site, and sites like it, the link checker fails on those URLs. Something like the W3C Link Checker doesn't seem to have that problem.

To use the utility, you have several options, but I generally install tools like this as Global packages so I can execute them from anywhere. With the utility installed, I simply open a terminal window and execute the following command:

checklinks

The utility then prompts you for all of its operational parameters, then starts scanning:

┌──────────────────┐
│                  │
│   Link Checker   │
│                  │
└──────────────────┘

by John M. Wargo (https://johnwargo.com)

√ Target site URL ... http://localhost:8080
√ Number of concurrent requests ... 100
√ Timeout value (in milliseconds) ... 10000
√ Select output options » Broken, Skipped
√ Save output to file? ... yes
√ Output file root filename (no extension) ... link-checker-results
√ Output format » Markdown (.md)

Starting scan...

--- scan activity here ---

Results successfully written to file: D:\dev\links\link-checker-results.md

Scan Results
==============================
Scanned: 1,079 links
Broken: 42 links
Skipped: 23 links
==============================

For my Random Errors site, the report, in markdown format, looks like this:

# Link Checker Results

**Created:** 11/13/2024, 5:24:33 PM

## Broken Links

| Status | URL |
|--------|-----|
| 404 | http://subname.mysite.com/ |
| 404 | https://capacitor-community-electron-docs-site.vercel.app/ |
| 403 | https://forums.adafruit.com/viewtopic.php?f=57&t=181830&p=884590 |
| 403 | https://forums.adafruit.com/viewtopic.php?f=57&t=182024 |
| 403 | https://forums.adafruit.com/viewtopic.php?p=949364&sid=f94be453911b5999954fb2cfb572ffd2 |
| 999 | https://www.linkedin.com/in/jmwargo/ |

## Skipped Links

| Status | URL |
|--------|-----|
|   0 | mailto:john@johnwargo.com |

---

Report created by <a href="https://github.com/johnwargo/link-checker" target="_blank">Link Checker</a> by John M. Wargo.

The report looks like this in a markdown editor:

Link checker results in a markdown editor

Give it a try and let me know if you like it.


Next Post: Added Automated Mode to Link Checker

Previous Post: Conditional Prompting Using Prompts

If this content helps you in some way, please consider buying me a coffee.

Header image: Photo by Ferenc Almasi on Unsplash.