npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

backlink-detector

v1.0.0

Published

Detect unauthorized external links (backlinks) in HTML content. Find links pointing to domains outside your whitelist.

Readme

backlink-detector

Detect unauthorized external links (backlinks) in HTML content. Find links pointing to domains outside your whitelist.

npm version License: MIT

Use Case

When managing website content (especially user-generated or third-party content), you may want to:

  • Detect unauthorized backlinks to external sites
  • Find links pointing to competitor domains
  • Audit content for SEO compliance
  • Remove unwanted external links while preserving content

Features

  • Domain whitelist - Specify allowed domains, detect everything else
  • Subdomain support - Automatically includes subdomains (www.example.com matches example.com)
  • Anchor text extraction - See what text is being used for links
  • HTML cleaning - Remove backlinks while preserving content
  • Zero dependencies - Uses native fetch API (Node.js 18+)
  • TypeScript - Full type definitions included
  • CLI & API - Use from command line or as a library

Installation

npm install backlink-detector

Or use directly with npx:

npx backlink-detector -f page.html -d example.com

CLI Usage

Detect backlinks in an HTML file

# Check HTML file - only allow links to example.com
backlink-detector -f page.html -d example.com

# Multiple allowed domains
backlink-detector -f page.html -d "example.com,mysite.org,blog.example.com"

Fetch and analyze a live page

backlink-detector -u https://example.com/page -d example.com

Get cleaned HTML (backlinks removed)

backlink-detector -f page.html -d example.com -c > cleaned.html

Output formats

# Detailed report
backlink-detector -f page.html -d example.com -r

# JSON output
backlink-detector -f page.html -d example.com --json

# List all links (no filtering)
backlink-detector -f page.html -l

Options

-f, --file <path>       HTML file to analyze
-u, --url <url>         URL to fetch and analyze
-d, --domains <list>    Comma-separated list of allowed domains (required)
-o, --output <path>     Output results to file
-c, --clean             Output cleaned HTML (backlinks removed)
-r, --report            Output detailed report
-l, --list              List all links without filtering
--json                  Output as JSON
-q, --quiet             Minimal output
-h, --help              Show help
-v, --version           Show version

API Usage

Detect Backlinks

import { detectBacklinks } from 'backlink-detector';

const html = `
  <html>
    <body>
      <a href="https://mysite.com/page">My Site</a>
      <a href="https://competitor.com/link">Competitor</a>
      <a href="https://spam-site.net">Spam</a>
    </body>
  </html>
`;

const result = detectBacklinks(html, {
  allowedDomains: ['mysite.com'],
});

console.log(result.stats);
// {
//   totalLinks: 3,
//   allowedLinks: 1,
//   externalLinks: 2,
//   uniqueExternalDomains: 2
// }

console.log(result.backlinks);
// [
//   { url: 'https://competitor.com/link', domain: 'competitor.com', anchorText: 'Competitor', ... },
//   { url: 'https://spam-site.net', domain: 'spam-site.net', anchorText: 'Spam', ... }
// ]

console.log(result.externalDomains);
// ['competitor.com', 'spam-site.net']

Remove Backlinks

import { removeBacklinks } from 'backlink-detector';

const html = '<p>Check out <a href="https://external.com">this link</a> for more.</p>';

const { html: cleanedHtml, removedCount } = removeBacklinks(html, {
  allowedDomains: ['mysite.com'],
});

console.log(cleanedHtml);
// '<p>Check out this link for more.</p>'

console.log(removedCount); // 1

Quick Checks

import { hasBacklinks, findExternalDomains } from 'backlink-detector';

// Check if any backlinks exist
if (hasBacklinks(html, ['mysite.com'])) {
  console.log('Backlinks found!');
}

// Get list of external domains
const domains = findExternalDomains(html, ['mysite.com']);
console.log(domains); // ['competitor.com', 'spam.net']

Extract All Links

import { extractLinks } from 'backlink-detector';

const { links, count } = extractLinks(html);

console.log(count); // 5
console.log(links);
// [
//   { url: 'https://...', anchorText: 'Click here', fullMatch: '<a href="...">Click here</a>' },
//   ...
// ]

Generate Report

import { getBacklinkReport } from 'backlink-detector';

const report = getBacklinkReport(html, {
  allowedDomains: ['mysite.com'],
});

console.log(report);
// ==================================================
// BACKLINK DETECTION REPORT
// ==================================================
//
// Total Links: 10
// Allowed Links: 3
// External Links (Backlinks): 7
// Unique External Domains: 4
// ...

Options

DetectOptions

interface DetectOptions {
  // List of allowed domains (required)
  allowedDomains: string[];

  // Include subdomains of allowed domains (default: true)
  // When true: "www.example.com" matches "example.com"
  includeSubdomains?: boolean;

  // Case insensitive domain matching (default: true)
  caseInsensitive?: boolean;
}

How Domain Matching Works

With includeSubdomains: true (default):

| Allowed Domain | URL Domain | Match? | |---------------|------------|--------| | example.com | example.com | ✅ | | example.com | www.example.com | ✅ | | example.com | blog.example.com | ✅ | | example.com | sub.blog.example.com | ✅ | | example.com | notexample.com | ❌ | | example.com | example.com.evil.com | ❌ |

Common Use Cases

SEO Audit

import { detectBacklinks, COMMON_SAFE_DOMAINS } from 'backlink-detector';

// Allow your domains + common safe domains
const allowedDomains = [
  'mysite.com',
  'myblog.com',
  ...COMMON_SAFE_DOMAINS, // Google, Facebook, Wikipedia, etc.
];

const result = detectBacklinks(html, { allowedDomains });

Content Moderation

import { removeBacklinks } from 'backlink-detector';

// Clean user-generated content
const userContent = await getUserContent();

const { html: cleanedContent } = removeBacklinks(userContent, {
  allowedDomains: ['mysite.com'],
});

// Save cleaned content
await saveContent(cleanedContent);

CI/CD Check

# Exit with error code 1 if backlinks found
backlink-detector -f dist/index.html -d mysite.com

# Use in CI pipeline
if backlink-detector -f build/index.html -d mysite.com -q; then
  echo "No backlinks found"
else
  echo "Unauthorized backlinks detected!"
  exit 1
fi

Requirements

  • Node.js 18+ (uses native fetch)

License

MIT License - see LICENSE file.

Credits

Built with ❤️ by Hayati Ali Keles