futurepress / epub.js

Enhanced eBooks in the browser.
http://futurepress.org
Other
6.46k stars 1.11k forks source link

Is the lib Node.js compatible? #1030

Open ffknob opened 4 years ago

ffknob commented 4 years ago

Hi there

I'd just would like to ask if the lib is compatible with Node.js.

This:

import { Book } from 'epubjs';

export const readEPub = (url: string): Promise<Book> => {
  return new Promise((resolve, reject) => {
    try {
      const book: Book = new Book(url, {});
      resolve(book);
    } catch (e) {
      reject(e);
    }
  });
};

export default { readEPub };

Results in:

XMLHttpRequest is not defined

Which makes sense, since we are not in the brwoser context.

So, what should I do in order to use the lib in the backend with Node.js?

Thank you!

kumar-muthu commented 4 years ago

Try using a headless browser preferably https://github.com/puppeteer/puppeteer and render your epub there

mcthulhu commented 4 years ago

Yes, I'm using it in a Node.js (Electron) desktop application; see https://github.com/mcthulhu/jorkens. It took a bit of trial and error to get it working in Electron, but it seems to be running well now and I'm starting to add functionality.