cheerio
Fast, flexible HTML parsing and manipulation for Node.js — a jQuery-like API for working with HTML documents on the server.
cheerio
General JSFast, flexible HTML parsing and manipulation for Node.js — a jQuery-like API for working with HTML documents on the server.
Fit
Bundle (gzip)
119.0 kB
316.2 kB raw
Install size includes transitive dependencies. Bundle size is gzipped browser payload.
Freshness
The Problem
Web scraping and HTML processing in Node.js requires parsing raw HTML into a traversable structure and selecting/manipulating elements — all without a browser DOM. Using regex for HTML parsing is fragile and error-prone.
What It Does
Cheerio parses HTML with htmlparser2 and exposes a jQuery-compatible API: $(selector) to select elements, .text(), .attr(), .html() to read content, and .find(), .parent(), .siblings() to traverse the tree. It's significantly faster than JSDOM because it doesn't simulate a full browser environment.
Installation
npm install cheerioUsage Example
import * as cheerio from 'cheerio';
const html = await fetch('https://news.ycombinator.com').then((r) => r.text());
const $ = cheerio.load(html);
// Extract all story titles
const stories: string[] = [];
$('.titleline > a').each((_, el) => {
stories.push($(el).text());
});
// Modify HTML
$('img').attr('loading', 'lazy');
const modifiedHtml = $.html();Related packages
Unified TypeScript SDK for building AI-powered apps — switch between 20+ LLM providers without rewriting code.
animejsGeneral JSLightweight JavaScript animation library with a tiny footprint and a powerful, expressive API.
AOSGeneral JSAn easy-to-use library that makes elements fade, slide, or zoom into view as the user scrolls down your page.
archiverGeneral JSStreaming interface for generating ZIP and TAR archives in Node.js — create compressed archives programmatically from files, directories, and buffers.
@formkit/auto-animateGeneral JS> Add smooth transitions to any element with a single line — zero-config animations for adds, removes, and moves.