node-html-parser

A very fast HTML parser that builds a lightweight DOM tree with full CSS3 selector support.

Library
npm
v9.0.3
1,246stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
83/100Excellent
Development Activity92
Maintenance84
Community56
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
66/100Good
Architecture74
Code Quality80
Innovation60
Learning Curve50

node-html-parser (published to npm as node-html-parser, developed under the taoqf/node-fast-html-parser repository) is a lightweight, high-performance HTML parser for Node.js and the browser. It parses raw HTML strings into a simplified DOM tree of HTMLElement, TextNode, and CommentNode instances, exposing a browser-like API — querySelector, querySelectorAll, closest, classList, innerHTML, and more — without needing a real DOM or headless browser.

Speed is the explicit design priority: the README ships its own benchmark suite comparing throughput against parse5, htmlparser2, cheerio, html5parser, and half a dozen other parsers. To get there it favors permissive parsing over strict HTML5-spec compliance — malformed markup such as unclosed tags or HTML4-style unclosed <td> elements is tolerated rather than rejected, which suits scraping and text-extraction workloads more than a spec-conformant renderer.

What You Get

  • A DOM-like tree of HTMLElement, TextNode, and CommentNode objects with parentNode/childNodes, classList, and attribute accessors mirroring the browser DOM API.
  • Full CSS3 selector support (querySelector, querySelectorAll, matches, closest, getElementsByTagName) powered by css-select through a custom adapter.
  • DOM mutation helpers — appendChild, insertAdjacentHTML, replaceWith, setAttribute(s), removeAttribute, before/after/prepend/append — for editing markup in place.
  • Configurable parse options (lowerCaseTagName, comment retention, void-tag lists, blockTextElements, nested-tag fixups) to trade strictness for speed depending on the input.
  • Dual ESM/CJS builds with bundled TypeScript type definitions, published for both import and require consumers.

Common Use Cases

  • Web scraping and crawler pipelines that need to extract text or links from HTML without booting a headless browser.
  • Server-side rendering and static-site pipelines that post-process or rewrite generated HTML fragments.
  • Data-extraction jobs (price/product scraping, RSS or feed HTML cleanup) that must handle large volumes of imperfect, real-world markup quickly.
  • Test suites and build tooling that need to assert on or transform HTML output without a browser environment.

Under The Hood

Architecture The public entry point (src/index.ts) exports a parse function and attaches the library’s other exports (HTMLElement, CommentNode, valid, Node, TextNode, NodeType) directly onto that function so both import { parse } and legacy require() consumers get the same surface; src/parse.ts is a one-line re-export of the parser from src/nodes/html.ts. The bulk of the logic lives in src/nodes/html.ts, a large hand-rolled state-machine-style tokenizer/builder that constructs the DOM tree directly rather than going through a separate lexer/AST stage. src/matcher.ts defines a local Adapter implementation (isTag, getChildren, getParent, existsOne, findAll, findOne, removeSubsets, etc.) matching css-select’s expected interface, which is the seam connecting the internal tree to css-select’s selectAll/selectOne/is functions that power querySelector and friends. Node types form a simple inheritance hierarchy off an abstract src/nodes/node.ts base, with src/nodes/text.ts and src/nodes/comment.ts as thin siblings to html.ts; src/void-tag.ts and src/back.ts are small focused helpers. It’s a flat, single-package architecture with no plugin system — clear node-type separation, but html.ts itself is dense, carrying both parsing and most of the public DOM API.

Tech Stack Written in TypeScript and built with tsdown (esbuild-based) plus tsc --emitDeclarationOnly, producing a dual ESM/CJS distribution wired through package.json’s exports map. Runtime dependencies are minimal and deliberate: css-select (^5.1.0) for CSS selector matching and entities (^8.0.0) for HTML entity decode/encode. The project uses Bun as its primary tooling (declared packageManager, used for install/build/test scripts) alongside mocha, should, spec, and blanket for testing and ts-node for running tests directly against source. A test/benchmark harness pits the library against parse5, htmlparser2, cheerio, html5parser, htmljs-parser, and others. GitHub Actions runs a build/test matrix across Node 22, 24, and 26 on every push and PR, with a separate tag-triggered workflow for npm publishing.

Code Quality test/tests/ contains dozens of focused test files covering the DOM API (clone, replaceWith, node-ranges, textcontent-encode, quoteattributes, unclosedtags, incomplete-blocktext) plus a dedicated test/tests/issues/ directory of regression tests tied to specific GitHub issues — a defensive, issue-driven suite rather than a purely feature-driven one. Both test:src (ts-node against source) and test:dist (compiled output) targets run in CI, catching build-artifact drift. The codebase is fully TypeScript with explicit interfaces (Options, Attributes, RawAttributes, KeyAttributes, and a locally redefined css-select Adapter type since css-select v5 doesn’t publicly export one), though some internal casts and non-null assumptions trade a bit of strictness for terseness. ESLint (typescript-eslint) and Prettier configs are present and enforced.

What Makes It Unique The library’s stated differentiator is raw parsing speed — the README carries its own comparative benchmark against nine-plus competing HTML parsers and is explicitly tuned to stay near the front of that pack rather than targeting full HTML5-spec conformance; malformed markup is tolerated by design instead of rejected. It also goes further than most lightweight parsers toward genuine DOM ergonomics: a real DOMTokenList-style classList with validation, structure/structuredText tree-inspection helpers, node ranges, and insertAdjacentHTML, aiming to feel like document.querySelector in Node rather than a plain object tree. The core ideas (DOM-like tree, CSS selector queries) are well precedented by libraries like cheerio, so the differentiation is the speed/ergonomics tradeoff rather than a novel parsing technique.

Used by 15 apps in this directory

JavaScript
95%
MIT

AnythingLLM

Developer Tools · Automation · AI Assistants

65,696

The all-in-one AI platform for private document chat, no-code agents, and local LLMs with zero setup friction.

View details
90
Repo Health
78
Technical
64
Dependency
Built with
JavaScript95%
Updated 3 days ago
Go
54%
Apache 2.0

Authgear

Authentication

2,028

Open-source, self-hostable authentication platform with passkeys, biometric login, SSO, MFA, and GraphQL admin API — a full Auth0/Clerk/Firebase alternative for SaaS and mobile apps.

View details
88
Repo Health
81
Technical
68
Dependency
Built with
Go54%
HTML25%
TypeScript18%
Updated 3 days ago
TypeScript
100%
MIT

Botpress

AI Assistants · AI Development · Customer Support

14,893

The open-source hub for building and deploying LLM-powered AI agents with TypeScript-first tooling, 40+ integrations, and a revolutionary code-execution agent framework.

View details
94
Repo Health
82
Technical
64
Dependency
Built with
TypeScript100%
Updated 3 days ago
Rust
67%
MIT

Bun

Developer Tools

95,895

An all-in-one JavaScript and TypeScript toolkit — one Rust-and-JavaScriptCore binary that replaces Node.js, npm, a bundler, and a test runner with faster equivalents.

View details
92
Repo Health
91
Technical
64
Dependency
Built with
Rust67%
C++19%
Updated yesterday
TypeScript
96%
Other

Cal.diy

Scheduling

48,218

The 100% MIT-licensed, community-driven scheduling platform — self-host your own booking infrastructure with no enterprise strings attached.

View details
95
Repo Health
86
Technical
65
Dependency
Built with
TypeScript96%
Updated yesterday
TypeScript
100%
Other

Dub

Marketing · Analytics

24,676

The open-source link attribution platform for short links, conversion tracking, and affiliate programs — powering 100M+ clicks monthly.

View details
80
Repo Health
78
Technical
62
Dependency
Built with
TypeScript100%
Updated 2 days ago
TypeScript
97%
Other

Formbricks

Forms Surveys · Marketing · Analytics

12,897

Open-source experience management platform for in-app, website, email, and link surveys — privacy-first and fully self-hostable.

View details
93
Repo Health
81
Technical
70
Dependency
Built with
TypeScript97%
Updated yesterday
Rust
72%
Other

iii

Developer Tools · Devops

18,679

Compose, extend, and observe every backend service in real time using three primitives: Workers, Functions, and Triggers.

View details
85
Repo Health
85
Technical
68
Dependency
Built with
Rust72%
TypeScript17%
Updated 2 days ago
TypeScript
38%
Apache 2.0

Label Studio

AI Development · Data Engineering

28,222

Label Studio is an open-source, multi-type data labeling platform that lets teams annotate images, text, audio, video, and time series data with a configurable XML-based UI and export annotations in formats ready for any ML framework.

View details
93
Repo Health
87
Technical
67
Dependency
Built with
TypeScript38%
JavaScript27%
Python25%
Updated today

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search