Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
E

epub

> 编程语言
Open source

node.js epub reader

362 stars0 likes0 views
WebsiteGitHub

About

node.js epub reader

epub

epub is a pure-JS module to parse EPUB electronic book files.

NB! Only ebooks in UTF-8 are currently supported!.

CLI

Read an Epub directly from your terminal

bash
URL="https://github.com/progit/progit2/releases/download/2.1.449/progit.epub"

npx epub "$URL"
# or
pnpx epub "$URL"

Installation

bash
npm install epub

Usage

javascript
import EPub from "epub";
const epub = new EPub(pathToFile);

Where

  • pathToFile is the file path to an EPUB file
  • Optional:
    • imageWebRoot is the prefix for image URL's. If it's /images/ then the actual URL (inside chapter HTML `` blocks) is going to be /images/IMG_ID/IMG_FILENAME, IMG_ID can be used to fetch the image form the ebook with getImage. Default: /images/
    • chapterWebRoot is the prefix for chapter URL's. If it's /chapter/ then the actual URL (inside chapter HTML `` links) is going to be /chapters/CHAPTER_ID/CHAPTER_FILENAME, CHAPTER_ID can be used to fetch the image form the ebook with getChapter. Default: /links/

Before the contents of the ebook can be read, it must be parsed:

javascript
await epub.parse();
console.log(epub.metadata.title);

const text = await epub.getChapter("chapter_id");

metadata

Property of the epub object that holds several metadata fields about the book.

javascript
epub.metadata;

Available fields:

  • creator Author of the book (if multiple authors, then the first on the list) (Lewis Carroll)
  • creatorFileAs Author name on file (Carroll, Lewis)
  • title Title of the book (Alice's Adventures in Wonderland)
  • language Language code (en or en-us etc.)
  • subject Topic of the book (Fantasy)
  • date creation of the file (2006-08-12)
  • description

flow

flow is a property of the epub object and holds the actual list of chapters (TOC is just an indication and can link to a # url inside a chapter file)

javascript
for (const chapter of epub.flow) {
	console.log(chapter.id);
}

Chapter id is needed to load the chapters getChapter

toc

toc is a property of the epub object and indicates a list of titles/urls for the TOC. Actual chapter and it's ID needs to be detected with the href property

getChapter(chapter_id)

Load chapter text from the ebook.

javascript
const text = await epub.getChapter("chapter1");

getChapterRaw(chapter_id)

Load raw chapter text from the ebook.

getImage(image_id)

Load image (as a Buffer value) from the ebook.

javascript
const { data, mimeType } = await epub.getImage("image1");

getFile(file_id)

Load any file (as a Buffer value) from the ebook.

javascript
const { data, mimeType } = await epub.getFile("css1");

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

TypeScript

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言