Download Game! Currently 71 players. Last logged in:LexelalexWhlxchDregasResin

Blitzer's Blog >> 72886

Back to blogs index
Posted: 02 Oct 2026 11:42 [ permalink ]
Here is a complete Node.js example that searches the Google Books API for a
free EPUB matching a query, extracts the download link, and saves the file
directly to your disk.
import fs from 'fs';

async function downloadFreeEpub(searchQuery, outputFilename) {
  // Construct the search query
  const apiUrl = `https://www.googleapis.com/books/v1/volumes?q=${encodeURIComp
onent(searchQuery)}&filter=free-ebooks&download=epub`;
  
  try {
    const response = await fetch(apiUrl);
    const data = await response.json();

    if (!data.items || data.items.length === 0) {
      console.log('No free EPUB books found for this query.');
      return;
    }

    // Find the first book in the results that explicitly has a download link
    const book = data.items.find(item => 
      item.accessInfo?.epub?.isAvailable && 
      item.accessInfo?.epub?.downloadLink
    );

    if (!book) {
      console.log('Books were found, but none had a direct EPUB download
link.');
      return;
    }

    const title = book.volumeInfo.title;
    const downloadUrl = book.accessInfo.epub.downloadLink;
    
    console.log(`Found: "${title}"`);
    console.log(`Fetching from: ${downloadUrl}`);

    // Download the actual EPUB file data
    const fileResponse = await fetch(downloadUrl);
    
    if (!fileResponse.ok) {
      throw new Error(`Failed to download file: ${fileResponse.statusText}`);
    }

    // Write the binary data to disk
    const buffer = Buffer.from(await fileResponse.arrayBuffer());
    fs.writeFileSync(outputFilename, buffer);
    
    console.log(`Successfully saved to ${outputFilename}`);

  } catch (error) {
    console.error('Error:', error);
  }
}

/ Example usage: Search for a public domain classic
downloadFreeEpub('Pride and Prejudice', 'pride_and_prejudice.epub');

This script leverages Node's native fetch and requires no external
dependencies.
The API request relies on &filter=free-ebooks to guarantee the results are
free of charge, and uses &download=epub to restrict the search strictly to
volumes with an EPUB format. After retrieving the JSON response, the script
parses the accessInfo object of the volume to confirm accessInfo.epub.isAvailab
le is true, extracting the exact target URL from accessInfo.epub.downloadLink.
Basic public data searches like this do not require OAuth authentication or an
API key. However, if your application makes a large volume of requests, you
can append &key=YOUR_API_KEY to the URL to utilize a higher quota limit.