Use jsdom and jQuery (server-side).

With jQuery you can delete all scripts, styles, templates and the like and then you can extract the text.

Example

(This is not tested with jsdom and node, only in Chrome)

jQuery('script').remove()
jQuery('noscript').remove()
jQuery('body').text().replace(/\s{2,9999}/g, ' ')
Answer from hgoebl on Stack Overflow
🌐
npm
npmjs.com › package › html-to-text
html-to-text - npm
Advanced converter that parses HTML and returns beautiful text. Inline and block-level tags. Tables with colspans and rowspans. Links with both text and href. Word wrapping. Unicode support. Plenty of customization options. ... Version 6 contains a ton of changes, so it worth to take a look at the full changelog.
      » npm install html-to-text
    
Published   Mar 23, 2023
Version   9.0.5
🌐
npm
npmjs.com › search
html to text - npm search
A powerful TypeScript library for converting HTML content to plain text while preserving structure and formatting.
🌐
npm
npmjs.com › package › @types › html-to-text
@types/html-to-text - npm
Latest version: 9.0.4, last published: 2 years ago. Start using @types/html-to-text in your project by running `npm i @types/html-to-text`. There are 138 other projects in the npm registry using @types/html-to-text.
      » npm install @types/html-to-text
    
🌐
npm
npmjs.com › package › text_to_html
text_to_html - npm
Convert text to HTML. Latest version: 0.2.8, last published: 2 years ago. Start using text_to_html in your project by running `npm i text_to_html`. There are no other projects in the npm registry using text_to_html.
      » npm install text_to_html
    
Published   Sep 25, 2020
Version   0.2.8
Author   Nathan Rugg
🌐
npm
npmjs.com › package › string-to-html
string-to-html - npm
May 8, 2017 - Latest version: 1.3.4, last published: 9 years ago. Start using string-to-html in your project by running `npm i string-to-html`. There are 2 other projects in the npm registry using string-to-html.
      » npm install string-to-html
    
Published   May 08, 2017
Version   1.3.4
Author   Rick Lancee
🌐
npm
npmjs.com › search
plain-text - npm search
Find URLs, email addresses, #hashtags and @mentions in plain-text strings, then convert them into HTML <a> links.
🌐
GitHub
github.com › html-to-text › node-html-to-text
GitHub - html-to-text/node-html-to-text: Advanced html to text converter · GitHub
CLI for html to text converter. ... Advanced html to markdown converter (WIP). ... Shared code. Only exists in the monorepo and bundled into published packages. ... Targeting Node.js version >=14. Monorepo uses NPM v7 workspaces (make sure v7 is installed when used with Node.js v14.)
Starred by 1.7K users
Forked by 226 users
Languages   JavaScript 95.8% | HTML 4.2%
Find elsewhere
🌐
npm
npmjs.com › package › convert-rich-text
convert-rich-text - npm
May 2, 2023 - Latest version: 6.1.0, last published: 3 years ago. Start using convert-rich-text in your project by running `npm i convert-rich-text`. There are 1 other projects in the npm registry using convert-rich-text.
      » npm install convert-rich-text
    
Published   May 02, 2023
Version   6.1.0
Author   Blake Thomson
🌐
npm
npmjs.com › package › @portabletext › to-html
@portabletext/to-html - npm
December 9, 2025 - Render Portable Text to HTML. Latest version: 5.0.0, last published: 15 days ago. Start using @portabletext/to-html in your project by running `npm i @portabletext/to-html`. There are 29 other projects in the npm registry using @portabletext/to-html.
      » npm install @portabletext/to-html
    
Published   Dec 09, 2025
Version   5.0.0
Author   Sanity.io
🌐
npm
npmjs.com › search
keywords:text to html - npm search
Fast and correct clip functions for HTML and plain text. ... arendjr• 2.2.0 • 4 years ago • 22 dependents • MITpublished version 2.2.0, 4 years ago22 dependents licensed under $MIT ... sindresorhus• 2.1.3 • 4 months ago • 86 dependents • MITpublished version 2.1.3, 4 months ago86 dependents licensed under $MIT ... Export to ...
🌐
Built In
builtin.com › articles › convert-html-plain-text
3 Ways to Convert HTML to Plain Text | Built In
I recently discovered the html-to-text package on NPM. This is the converter library that parses HTML and returns beautiful text. It comes with many options to convert it to plain text, including: wordwrap, tags, whitespaceCharacters and ...
🌐
npm
npmjs.com › package › js-to-html
js-to-html - npm
January 31, 2026 - Create HTML text from JS object. Latest version: 1.3.5, last published: 3 months ago. Start using js-to-html in your project by running `npm i js-to-html`. There are 14 other projects in the npm registry using js-to-html.
      » npm install js-to-html
    
Published   Jan 31, 2026
Version   1.3.5
🌐
npm
npmjs.com › package › html2plaintext
html2plaintext - npm
Granular tokens are now limited to 90 days and require 2FA by default. Update your CI/CD workflows to avoid disruption. Learn more.× ... var h2p = require('html2plaintext') h2p('<p>Hello,\n &amp; <em>how are <a href="https://me.com">you</a>?</em></p>') // => "Hello, & how are you?"
      » npm install html2plaintext
    
Published   Nov 17, 2021
Version   2.1.4
Author   Kurt Ericson
🌐
Developerindian
developerindian.com › articles › convert-html-text-to-plain-text-node-js
Convert HTML to plain text using Node.js
March 15, 2025 - There is serveral method to convert HTML into plan text here we can use replace function of node js. This function took two parameters in argument. First argument is source value of string.
🌐
npm
npmjs.com › package › @wcj › markdown-to-html
@wcj/markdown-to-html - npm
February 3, 2026 - Latest version: 3.0.6, last published: 3 months ago. Start using @wcj/markdown-to-html in your project by running `npm i @wcj/markdown-to-html`. There are 13 other projects in the npm registry using @wcj/markdown-to-html.
      » npm install @wcj/markdown-to-html
    
Published   Feb 03, 2026
Version   3.0.6
🌐
Snyk
snyk.io › advisor › html-to-text › html-to-text code examples
Top 5 html-to-text Code Examples | Snyk
function extractSummary (content, ext) { var text = ext === 'html' ? toText.fromString(content, {ignoreHref: true, ignoreImage: true, wordwrap: 99999}) : content var summary = '' var chars = text.split('') for (var i = 0; i &lt; chars.length; i++) { var ch = chars[i] summary += ch if (ch === '\n' &amp;&amp; chars[i + 1] === '\n' &amp;&amp; summary.length &gt; 300) { // paragraph break } if (ch === ' ' &amp;&amp; summary.length &gt;= 450) { // word break break }
🌐
npm
npmjs.com › package › markdown-to-html
markdown-to-html - npm
Latest version: 0.0.13, last published: 9 years ago. Start using markdown-to-html in your project by running `npm i markdown-to-html`. There are 13 other projects in the npm registry using markdown-to-html.
      » npm install markdown-to-html
    
Published   Oct 26, 2016
Version   0.0.13