Creating EPUB documents from Fictionpress stories

I consume a lot of written media on my Kindle, and I’m often frustrated when I have to use my mobile phone or computer to read online content. I needed a new project and I was hearing a lot about Node.js. In order to learn more about Node.js, I decided to write a couple of libraries to grab content from a specific website (Fictionpress) and convert it into a format that my Kindle could use.

The two libraries are now available on NPM, a Node.js package manager.

Sample Code

'use strict';

// DEPENDENCIES
var fpScraper = require('fictionpress-scraper');
var epub = require('quick-epub');

// Replace null with a valid storyID
var storyID = null;

// Grab the story data, then generate an EPUB document
fpScraper.getStory(storyID).then(function(story){
 // Tweak received data so that it matches expected format for quick-epub
 var epubData = {
  title: story.title,
  author: story.author.name,
  publisher: 'Fictionpress',
  description: story.summary,
  contents: story.content,
  output: story.id + '.epub'
 };

 // Generate EPUB
 return epub.createFile(epubData);
}).then(function(){
 console.log('Fictionpress EPUB generated.');
}).catch(function(error){
 console.error(error);
});