cheerio
Cheerio is a fast, flexible, and lean implementation of jQuery designed specifically for server-side HTML parsing and manipulation. Cheerio parses HTML document…
Installation
npm install cheerio
yarn add cheerio
pnpm add cheerio
Import
import * as cheerio from 'cheerio';
Quick Example
import * as cheerio from 'cheerio';
const html = '<h2 class="title">Hello</h2><p>World</p>';
const $ = cheerio.load(html);
console.log($('h2').text()); // 'Hello'
console.log($('.title').attr('class')); // 'title'About cheerio
Cheerio is a fast, flexible, and lean implementation of jQuery designed specifically for server-side HTML parsing and manipulation. Cheerio parses HTML documents into a DOM-like structure and provides jQuery's familiar API for traversing, selecting, and manipulating elements without the overhead of a full browser environment. Using CSS selectors with the $() function, you can find elements, read and modify attributes, extract text content, manipulate classes, and restructure HTML documents. Cheerio is commonly used for web scraping — extracting data from HTML pages by selecting elements and reading their content. The library handles malformed HTML gracefully using parse5 or htmlparser2 as underlying parsers, making it robust for processing real-world web pages. Cheerio supports XML parsing mode for working with RSS feeds and other XML documents. Unlike jsdom which creates a full browser environment with window, document, and event handling, Cheerio focuses exclusively on DOM manipulation without JavaScript execution, making it significantly faster and lighter. Cheerio is the standard tool for server-side HTML manipulation in the Node.js ecosystem.
Quick Facts
| Package | cheerio |
| Category | Utility |
| Weekly Downloads | 7M+ |
| License | MIT |
| Install | npm install cheerio |
Related Packages
jsdom is a pure JavaScript implementation of web standards, primarily the WHATWG DOM and HTML Standa…
Puppeteer is a Node.js library developed by Google that provides a high-level API to control Chrome …
Axios is a promise-based HTTP client for the browser and Node.js that provides an elegant and powerf…
Node-fetch is a lightweight module that brings the browser's Fetch API to Node.js, providing a famil…
Browse npm Packages by Category
Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.