How to Get a Medium Article in Markdown Format

Using Medium API Javascript Library

Markdown is a lightweight and easy-to-read format widely used for writing and formatting text. With the Medium API, you can easily extract the Markdown version of any Medium article using its unique ID. The result is a well-structured Markdown document containing the article’s title, headers, images, links, and more.

This guide walks you through the process of fetching a Medium article's Markdown format using the medium-api-js library.

Prerequisites

Before you get started, ensure the following:

Step-by-Step Code Explanation

1. Import Necessary Modules

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

dotenv.config();

The medium-api-js library is used to interact with the Medium API, and dotenv helps manage environment variables securely. By calling dotenv.config(), the application loads API keys or sensitive configurations from the .env file.

2. Initialize the Medium API Client

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

An instance of the Medium client is created, and the RapidAPI key is passed as an argument. This key authenticates your requests to the Medium API.

3. Specify the Article ID

const articleId = '67fa62fc1971';

The articleId uniquely identifies the article on Medium. Replace '67fa62fc1971' with the ID of the article you want to fetch in Markdown format.

4. Fetch and Log the Markdown Content

medium.getArticleMarkdown(articleId).then(data => {
    console.log('Article Markdown:', data);
});

The getArticleMarkdown method is called with the article ID. This returns a promise that resolves to the article's Markdown data, which is then logged to the console.

Running the Code

Save the script as getArticleMarkdown.js and run it using the following command:

node getArticleMarkdown.js

Output and Explanation

When the script executes successfully, it outputs the Markdown content of the specified article:

Key Elements of the Output

Potential Use Cases

Summary

With Medium API, fetching a Medium article's Markdown format becomes a seamless process, enabling you to integrate, analyze, or repurpose content effortlessly.

Whether you’re migrating content, analyzing articles, or building a custom reader, this script can save you a lot of manual effort. If you have any questions or need assistance with Medium API, feel free to contact nishu@mediumapi.com.

Happy coding!

nishu@mediumapi.com