How to check for broken links with n8n

Spread the love

How to check for broken links with n8n

In the digital landscape of 2026, maintaining a healthy website is no longer just about content; it is about connectivity. Broken links are the digital equivalent of a bridge leading to a cliff, frustrating users and signaling to search engines that your site is neglected. Learning how to check for broken links with n8n allows you to automate this maintenance, ensuring your site remains an SEO powerhouse. ๐Ÿš€

Automating your link audits saves hours of manual labor and provides real-time alerts before a user ever sees a 404 error. This guide will walk you through building a custom, high-performance link checker using n8nโ€™s flexible workflow engine. Whether you are managing a small blog or a massive enterprise portal, this automation is your first line of defense. ๐Ÿ›ก๏ธ

Why Automate Your Link Audits?

By 2026, search engine algorithms have become incredibly sensitive to “user friction.” A single broken link can negatively impact your Core Web Vitals and overall authority. When you know how to check for broken links with n8n, you transform a reactive chore into a proactive strategy. ๐Ÿ› ๏ธ

Manual checking is like trying to find a needle in a haystack while blindfolded. Automation, specifically through n8n, acts like a high-powered magnet, pulling those needles out instantly. This ensures your link equity remains intact and your bounce rates stay low. ๐Ÿ“ˆ

The Core Workflow Logic

To build a link checker, we first need to fetch the content of our target page. We then need to extract every URL found within the HTML and test each one to see if it returns a “200 OK” status. Think of it like a mail sorter at a post office checking every address to ensure it actually exists before sending the truck. ๐Ÿ“ฎ

The workflow typically starts with an HTTP Request node to grab the HTML. This is followed by a Code Node that uses logic to find all the links. Finally, we loop through these links and send another HTTP request to each, checking for failures. ๐Ÿ”—

Parsing Links with the Code Node

While n8n has many built-in nodes, a small snippet of JavaScript is the most efficient way to extract links from raw HTML. This “Digital Detective” logic scans the entire text for anything matching the structure of a hyperlink. This method is significantly faster than using multiple DOM-parsing nodes. ๐Ÿ•ต๏ธโ€โ™‚๏ธ

The following code block is designed to be pasted directly into an n8n Code Node. It takes the HTML from the previous step and returns an array of unique URLs. This makes it incredibly easy for the rest of your workflow to process each link individually. ๐Ÿ’ป


// This script acts as a high-speed scanner, identifying all 'href' attributes in the HTML content.
// Think of it as a specialized filter that ignores the 'noise' and only keeps the destination URLs.

const htmlContent = $node["HTTP Request"].json["data"]; // Grab the HTML string from the previous node
const linkPattern = /href="([^"]*)"/g; // This is our 'Search Warrant' to find URLs
let foundLinks = [];
let match;

// We use a loop to find every occurrence of a link in the text.
while ((match = linkPattern.exec(htmlContent)) !== null) {
  const url = match[1];
  // We only care about links that start with 'http' to avoid mailto: or tel: links.
  if (url.startsWith('http')) {
    foundLinks.push({ url: url });
  }
}

// Removing duplicates ensures we don't check the same link twice and waste resources.
const uniqueLinks = [...new Map(foundLinks.map(item => [item.url, item])).values()];

return uniqueLinks;

The code above uses a Regular Expression (regex) to identify URLs. Regex is essentially a “pattern matcher” that tells the computer exactly what a link looks like. By filtering out non-HTTP links, we ensure our workflow doesn’t crash trying to “ping” a phone number or an email address. ๐Ÿงช

Comparison: Manual vs. n8n vs. SaaS

Choosing the right tool depends on your scale and technical comfort. Here is how n8n stacks up against other methods in 2026. ๐Ÿ“Š

Feature Manual Checking Paid SaaS Tools n8n Automation
Cost Free (Time Expensive) $50 – $200/mo Free (Self-hosted) / Low Cost
Scalability Very Low High Infinite
Frequency Whenever you remember Scheduled Real-time or Scheduled
Customization None Moderate Total Control

Pros and Cons of n8n Link Checking

Pros: ๐Ÿ’Ž

  • Zero Cost: No per-link fees like some commercial SEO platforms.
  • Deep Integration: Send broken link alerts directly to Slack, Discord, or your ticketing system.
  • Privacy: Your data never leaves your infrastructure if you are self-hosting n8n.
  • Flexibility: You can program it to ignore certain domains or check only specific parts of your site.

Cons: โš ๏ธ

  • Learning Curve: Requires a basic understanding of HTTP requests and JSON.
  • Resource Intensive: Checking thousands of links simultaneously can strain your server.
  • Rate Limiting: If you check too fast, websites might temporarily block your IP address.

How to Use It Properly (Step-by-Step)

To master how to check for broken links with n8n, follow these steps to ensure a robust workflow. ๐Ÿ“

  1. Trigger: Use a ‘Schedule’ node to run the check once a week or a ‘Webhook’ to trigger it after a site update.
  2. Fetch Content: Use the ‘HTTP Request’ node to GET your website’s main URL. Set the response format to ‘String’.
  3. Extract: Insert the Code Node provided above to extract all the unique URLs from the page.
  4. Split: Use the ‘Split In Batches’ node to process links in groups of 5 or 10. This prevents your workflow from overwhelming the server.
  5. Verification: Use another ‘HTTP Request’ node inside the loop to check the status of each URL. Set it to ‘Ignore SSL Issues’ if needed.
  6. Filter: Use an ‘IF’ node to check if the status code is NOT 200. Anything else (404, 500, 403) is a potential broken link.
  7. Notify: Connect the ‘False’ branch of your IF node to a Slack or Email node to alert your team.

It is vital to use the ‘Split In Batches’ node. Think of it like a revolving door at a busy hotel. If 500 links try to enter the “check” node at once, the system might jam; batches keep everything moving smoothly. ๐Ÿจ

Tips and Tricks for Success

Always add a Wait Node if you are checking many links on the same external domain. This “politeness delay” prevents you from being identified as a bot and getting your IP blacklisted. A 1-second delay between checks is usually sufficient. โณ

Consider using the Error Trigger node. In n8n, if a link is totally dead, the HTTP Request node itself might fail. By using an Error Trigger, you can catch these “hard failures” and log them just like a standard 404 error. ๐Ÿšจ

Finally, filter out social media links if you are just doing a quick health check. Sites like LinkedIn and Facebook often return a 999 or 403 status to automated requests, which can lead to false positives in your report. ๐Ÿ™…โ€โ™‚๏ธ

Frequently Asked Questions

Can n8n check links inside PDFs?
Yes, but you will need an additional node to convert the PDF to text before running the link extraction logic. n8n has community nodes that can handle this conversion. ๐Ÿ“„

How do I handle links that require a login?
You can configure the ‘HTTP Request’ node to use Authentication (Basic Auth, Header Auth, or OAuth2). This allows n8n to check links behind a member’s area or dashboard. ๐Ÿ”‘

Is there a limit to how many links I can check?
The limit is mostly based on your server’s memory and the timeout settings of your n8n instance. For checking thousands of links, it is best to use a database node to track progress across multiple workflow executions. ๐Ÿ’พ

Ready to take your automation skills to the next level? Explore more guides and tutorials at n8nnode.com.


Spread the love

Leave a Comment