Nowadays, it is quite possible to reach global news on the internet. Websites such as Google News and Microsoft MSN provide their users with news from thousands of sources around the world through a single platform. They also support more than one language country. There are many REST APIs available from the market that provide developers with multiple news source data. One of them is the mediastack live and historical news API.
APIs that provide live and historic news articles enable developers and businesses to obtain last-minute and historical data from multiple sources with a single HTTP request. In this article, we will introduce mediastack API, which is the most popular news REST API today. Then we will explain how we can integrate the historical news endpoint, which is an endpoint of the mediastack API, into the Node.js programming language.Table of Contents
What Is the mediastack API?

Creating a Historical News Application
In this section, we will integrate the historical news endpoint of the mediastack API into the Node.js programming language. Firstly, we need to gain access to the mediastack API to perform an integration. For this, we will sign up for one of the affordable subscription plans offered by the mediastack. Then, after obtaining our API key on the dashboard page that opens, we can start developing our application. For this, let’s open a terminal in the file path where we will develop the application and create the Node.js project by running the command with the following default settings.npm init
After installing our Node.js application with the default setting, we will open a file named ‘index.js’ in the application directory. Then we will install the libraries that we will use in the application with the following command.
npm i express request
After adding the necessary libraries to our project, we can now write code. Let’s add the following code to the ‘index.js’ file.
const express = require('express');
const app = express();
let request = require('request');
let apiKey = 'YOUR-API-KEY';
const port = 5000;
app.get('/api/historical-news', (req, res) => {
let url = `https://api.mediastack.com/v1/news?access_key=${apiKey}&date=2020-07-17`;
request(url, function (err, response, body) {
if(err){
console.log('error:', error);
} else {
console.log('body:', body);
res.json(body);
}
})
})
app.listen(port, () => {
console.log(`Running at http://localhost:${port}`);
});
After running the application, let’s send an HTTP GET request from the URL below to the API we developed.
http://localhost:5000/api/historical-news
Some of the historical news we obtained from the mediastack API as a result of HTTP GET request is as follows.
{
"pagination": {
"limit": 100,
"offset": 0,
"count": 100,
"total": 293
},
"data": [
{
"author": "CNN Staff",
"title": "This may be the big winner of the market crash",
"description": "This may be the big winner of the market crash",
"url": "http://rss.cnn.com/~r/rss/cnn_topstories/~3/KwE80_jkKo8/a-sa-dd-3",
"source": "CNN",
"image": "https://cdn.cnn.com/cnnnext/dam/assets/150325082152-social-gfx-cnn-logo-super-169.jpg",
"category": "general",
"language": "en",
"country": "us",
"published_at": "2020-07-17T23:35:06+00:00"
},
[...]
]
}

