Dev.to WebDev 🛠 Dev 👁 0 📖 6 min read

How to check if your directory backlinks are dofollow, nofollow or gone (a 60-line Node.js script)

To check a directory backlink, fetch the listing page, find the <a> that points to your domain, and read three things: the rel attribute on that link, the page's robots meta tag, and the X-Robots-Tag header. A link with

To check a directory backlink, fetch the listing page, find the <a> that points to your domain, and read three things: the rel attribute on that link, the page's robots meta tag, and the X-Robots-Tag header. A link with no nofollow, ugc or sponsored on an indexable page is the one that counts as dofollow. The script below does this for a whole list in one run.

TL;DR: put your listing URLs in a text file, run node check-links.mjs listings.txt your-domain.com, and you get a table: status code, whether your link is on the page, its rel value and whether the page allows indexing.

Why check backlinks by hand at all?

Because the label a directory gives itself and the link it actually renders are often different. I submitted one product to a long list of startup directories and then re-read every live listing. Out of 50 live listings, 22 carried a plain followed link. The rest were nofollow, ugc or sponsored, even on several sites that are listed as "dofollow" in popular spreadsheets.

There is a second reason. Links disappear. A listing can be live on Monday and moved behind a login, renamed or deleted a month later. If you report backlinks to a client or track your own link profile, you need a check you can rerun.

What exactly makes a link "dofollow"?

There is no dofollow attribute. A link is "followed" when it has none of the values Google documents for qualifying outbound links: nofollow, ugc and sponsored (Google Search Central: qualify outbound links). The values can be combined, for example rel="ugc nofollow", which is what Medium and many forums use.

The page level matters too. A <meta name="robots" content="noindex, nofollow"> tag or an X-Robots-Tag: nofollow header applies to every link on the page (Google: robots meta tag and X-Robots-Tag). New accounts on some platforms get exactly that until a moderator approves them, so a link can look clean in the HTML and still be ignored.

What you see What it means for the link
<a href="https://you.com"> on an indexable page followed
rel="nofollow", rel="ugc" or rel="sponsored" not followed (any of them)
rel="noopener noreferrer" only followed, these values are about the browser, not search
page has noindex or nofollow in meta robots page links are not counted, whatever their rel says
your link is missing from the HTML removed, moved, or rendered by JavaScript (check in a browser)

The noopener row trips people up. noopener and noreferrer control the browser's window.opener and the Referer header (MDN: rel attribute). They say nothing to search engines.

The script

Node 18 and later ship fetch globally (Node.js globals), so there is nothing to install. Save this as check-links.mjs:

// node check-links.mjs listings.txt your-domain.com
import fs from 'node:fs';

const [file, domain] = process.argv.slice(2);
if (!file || !domain) {
  console.error('usage: node check-links.mjs <file with one URL per line> <your-domain.com>');
  process.exit(1);
}
const urls = fs.readFileSync(file, 'utf8').split('\n').map((s) => s.trim()).filter(Boolean);
const host = domain.replace(/^www\./, '').toLowerCase();

const attr = (tag, name) => {
  const m = tag.match(new RegExp(`\\b${name}\\s*=\\s*("([^"]*)"|'([^']*)'|([^\\s>]+))`, 'i'));
  return m ? (m[2] ?? m[3] ?? m[4] ?? '').trim() : null;
};

async function check(url) {
  try {
    const res = await fetch(url, {
      redirect: 'follow',
      signal: AbortSignal.timeout(20000),
      headers: { 'user-agent': 'Mozilla/5.0 (link check)' },
    });
    const html = await res.text();
    const metaTag = (html.match(/<meta[^>]+name\s*=\s*["']?robots["']?[^>]*>/i) || [''])[0];
    const robots = [attr(metaTag, 'content') || '', res.headers.get('x-robots-tag') || ''].join(' ').toLowerCase();
    const ours = [...html.matchAll(/<a\b[^>]*>/gi)].map((m) => m[0]).filter((tag) => {
      const href = attr(tag, 'href') || '';
      try { return new URL(href, url).hostname.replace(/^www\./, '').toLowerCase().endsWith(host); }
      catch { return false; }
    });
    const rels = ours.map((tag) => (attr(tag, 'rel') || '').toLowerCase());
    const followed = rels.some((r) => !/\b(nofollow|ugc|sponsored)\b/.test(r));
    return {
      url,
      status: res.status,
      found: ours.length,
      rel: ours.length ? [...new Set(rels.map((r) => r || '(none)'))].join(' | ') : '-',
      indexable: !/\bnoindex\b/.test(robots),
      verdict: !ours.length ? 'MISSING' : /\bnofollow\b/.test(robots) || !followed ? 'not followed' : 'followed',
    };
  } catch (e) {
    return { url, status: 'error', found: 0, rel: '-', indexable: '-', verdict: e.name };
  }
}

const rows = [];
for (const u of urls) rows.push(await check(u));
console.table(rows);

Run it:

node check-links.mjs listings.txt website.show

You get one row per listing with the HTTP status, how many links to your domain the HTML contains, their rel values, whether the page is indexable, and a verdict. It checks one URL at a time on purpose: a directory that sees twenty parallel requests from one IP may answer with a challenge page instead of the listing.

How do I read the results?

Start with the verdict column, then look at the exceptions.

  1. followed: the link is in the HTML, at least one copy has no qualifying rel, and the page is indexable.
  2. not followed: every copy of your link is qualified, or the page tells crawlers not to follow links. Still useful for visitors and for AI answers that quote the page, just not for link equity.
  3. MISSING: open the URL in a browser. If you see your listing there, the site renders it with JavaScript and a plain fetch cannot see it. If you do not see it, the listing moved or was removed.
  4. status 403 or 429: the site blocked the check, not necessarily the listing. Recheck from a browser before you write it off.

Common mistakes when checking backlinks

  • Trusting a spreadsheet's "dofollow" column. Directories change their templates. Check the live page.
  • Matching the wrong link. Your product name often appears in the directory's own internal link (/product/your-name). Match on your domain in href, as the script does, not on the text.
  • Ignoring the page-level robots tag. A clean <a> on a noindex, nofollow page does nothing for you.
  • Reading noopener as nofollow. It is not.
  • Checking only once. Rerun the list monthly. Listings that vanish are a normal part of directory work.

Where to get the list of listings in the first place?

If you submitted by hand, your inbox and your notes are the list. If you are still choosing where to submit, I keep a filterable directory list on website.show with the link type each directory gave in real submissions, its Domain Rating and the sign-up it needs. Whatever list you use, treat the link type as a claim and verify it with a check like this one after the listing goes live.

FAQ

Does a nofollow directory link have any value?
It can bring visitors, and the page can be read and quoted by search engines and AI assistants. It does not pass link equity the way a followed link can.

Why does the script say MISSING when I can see my listing?
The listing is rendered in the browser by JavaScript. Use a headless browser such as Playwright for those few sites, or check them by hand.

Is rel="ugc nofollow" worse than rel="nofollow"?
For link equity both mean "not followed". ugc only tells search engines the link sits in user-generated content.

How often should I recheck?
Monthly is enough for most products. Recheck right away before you send a report to anyone.

Can I run this on hundreds of URLs?
Yes. It runs one at a time, so a few hundred listings take a few minutes. Keep it sequential to avoid being rate-limited.

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.