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.
Before you get started, ensure the following:
.env
file to securely store your API key.npm install medium-api-js dotenv
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.
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.
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.
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.
Save the script as getArticleMarkdown.js
and run it using the following command:
node getArticleMarkdown.js
When the script executes successfully, it outputs the Markdown content of the specified article:
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!