# epub

> Parse EPUB electronic book files with Node.JS

Latest version **2.1.1** (published 2026-02-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install epub
pnpm add epub
yarn add epub
bun add epub
```

Provides the command `epub`.

## Health

**Score 65/100 (B)** — status: stable.

Positive: has types; esm support; no vulnerabilities; has provenance; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 2.1.1 |
| Published | 2026-02-23 |
| First published | 2011-06-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=22.6.0 |
| Dependencies | 2 |
| Unpacked size | 44.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| Author | Andris Reinman |
| Maintainers | julien-c, andris |
| Keywords | books, epub |

## Links

- npm: https://www.npmjs.com/package/epub
- Repository: https://github.com/julien-c/epub
- Homepage: http://github.com/julien-c/epub
- Issues: https://github.com/julien-c/epub/issues
- npm.io page: https://npm.io/package/epub

## Dependencies (2)

- [jszip](https://npm.io/package/jszip.md) ^3.10.1
- [fast-xml-parser](https://npm.io/package/fast-xml-parser.md) ^5.3.7

## Recent versions

- 2.1.1 (latest) — 2026-02-23
- 2.0.0-rc.1 (next) — 2026-02-23
- 0.1.3 (0.1.3) — 2014-03-31
- 2.1.0 — 2026-02-23
- 2.0.1 — 2026-02-23
- 2.0.0 — 2026-02-23
- 1.3.0 — 2025-01-17
- 1.2.1 — 2020-05-09
- 1.2.0 — 2019-11-05
- 1.1.0 — 2018-09-28
- 0.2.0 — 2017-10-17
- 0.1.6 — 2015-01-09
- 0.1.5 — 2014-04-02
- 0.1.4 — 2014-03-31
- 0.1.2 — 2013-12-16
- … 2 more at https://npm.io/package/epub/versions

## README

# epub [![CI](https://github.com/julien-c/epub/actions/workflows/ci.yml/badge.svg)](https://github.com/julien-c/epub/actions/workflows/ci.yml)

**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

```js
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 `<img>` 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 `<a>` 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:

```js
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.

```js
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)

```js
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.

```js
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.

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

## getFile(file_id)

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

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

---
_Source: https://npm.io/package/epub · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
