How to Save a Medium Article as HTML

Using Medium API JS Package

Medium is one of the most popular blogging platforms, and having the ability to fetch and save an article as HTML can be incredibly useful. Whether you're archiving content, customizing its display, or embedding it into another application, fetching the HTML version of a Medium article opens up countless possibilities.

In this article, you'll learn how to retrieve and save a Medium article as HTML using the medium-api-js package.

Prerequisites

Before diving into the steps, make sure you have the following:

Code Explanation

This code uses the medium-api-js library to fetch the HTML content of a specific Medium article.

Here is a step-by-step breakdown:

Step 1: Import Dependencies

import Medium from 'medium-api-js';
import dotenv from 'dotenv';

dotenv.config();

Step 2: Initialize the Medium API Client

const medium = new Medium(process.env.RAPIDAPI_KEY);

Step 3: Define Parameters for the Request

const articleId = '67fa62fc1971';

const fullPage = true;  // Set to true if you want the full page
const styleFile = "dark.css"; // Set the css file name if you want to include the style file

Step 4: Fetch and Log the Article HTML

medium.getArticleHTML(articleId, fullPage, styleFile)
    .then(data => {
        console.log('Article HTML:', data);
    });

Command to Run the Script

Save the script as getArticleHTML.js and run the following command in your terminal:

node getArticleHTML.js

Output Explanation

If the request is successful, the script logs the HTML content of the specified article:

Potential Use Cases

Summary

With medium-api-js, fetching and saving Medium articles as HTML becomes a straightforward task. This script demonstrates how to retrieve an article's HTML content with customizable options for the full page and styling. Whether you’re building an archive or enhancing content presentation, this technique can be incredibly beneficial.

For questions or further assistance with the Medium API, feel free to reach out at nishu@mediumapi.com. Happy coding!

nishu@mediumapi.com