Fetching articles from specific lists on Medium can help developers and content creators organize data for analytics, create curated collections, or power content-based applications.
In this article, you'll learn how to fetch all articles from a given Medium list ID using the medium-api-js package, logging the details to the console.
Before running the code, ensure you meet the following requirements:
medium-api-js
Library: Install the library using npm or yarn:npm install medium-api-js dotenv
RAPIDAPI_KEY
..env
file in the same directory as your script with the following content:RAPIDAPI_KEY=your_api_key_here
The following modules are imported:
import Medium from 'medium-api-js';
import dotenv from 'dotenv';
medium-api-js
library, it provides methods to interact with Medium's API..env
file, which is essential for keeping your API keys secure.dotenv.config();
The dotenv.config()
method loads the .env
file into process.env
, making your API key accessible during runtime.
const medium = new Medium(process.env.RAPIDAPI_KEY);
An instance of the Medium
class is created, with the API key passed from process.env.RAPIDAPI_KEY
.
medium.getListArticles('3d8f744f5370').then(data => {
console.log('List Articles:', data);
});
getListArticles('3d8f744f5370')
: Fetches all articles belonging to the list with ID 3d8f744f5370
.
.then(data => {...}
: Handles the resolved promise, where the list data is logged to the console.
Save the script as getListArticles.js
and execute it using Node.js:
node getListArticles.js
Upon running the script, the following output is logged:
Key Components:
3d8f744f5370
). This code provides a straightforward way to fetch articles from a Medium list using medium-api-js
. It is highly extensible and can be adapted for various use cases, from analytics to custom applications.
For any questions or help with the Medium API, feel free to contact me at nishu@mediumapi.com.
Happy coding!