Unparalleled suite of productivity-boosting Web APIs & cloud-based micro-service applications for developers and companies of any size.


How To Create A News Web App In Node.js With A Media API?

We have been exploring different APIs from the apilayer. In one of the demonstrations, we have utilized Node.js to scrape data from web pages. In this post, we will use Node.js and MediaStack API to create a news web app.

So this Node.js web app connects to the MediaStack API and shows results in a user-friendly way with Express, EJS, Axios, and some CSS! Another great API that can be paired with the mediastack API is a geolocation API from ipstack.

First, let me introduce the MediaStack API and its features. Stay tuned for real-world Node.js applications with MediaStack API.

By the way, we have a bonus at the end of the article!

What is MediaStack?

MediaStack API is a powerful REST API for live news and blog articles. MediaStack – offers the #1 solution for all your media-related requirements in one place.

Tap into a world of live news data feeds from 7,500 news sources worldwide. Monitor brands and access breaking news events around the world.

Our REST API is built upon scalable apilayer cloud infrastructure and delivers news results in lightweight and easy-to-use JSON format. Moreover, this RESTful web service is platform agnostic and can be integrated with any technology in the market.

MediaStack API is fully automated and updated every minute.

  • Real-Time News Data
  • Historical News Data
  • News Headlines
  • 7,500+ News Sources
  • 50+ Countries 
  • 13 Languages Available

How to get started with MediaStack API?

If you do not have an account yet, please make sure to get a free API access key by subscribing to the Free subscription plan. It gives limited access to the media sources to test it out before production.

Here is an example of a simple request:

If you are in a higher subscription plan you can have different functionalities and a more secure connection. For instance, to connect to the MediaStack API using 256-bit HTTPS (SSL) encryption, you will need the Standard or higher plan.

MediaStack API features

Live News – You can access real-time news articles using the news endpoint. Moreover, you can filter your news results by giving optional parameters. Here is an example of requesting live news and filtering data from different countries

Categorizing – Categorize news categories. For instance, get only sports and technology news

Keywords – You can use this parameter to search for exact news from the sources

Date – This parameter can handle historical data. For instance, you can specify the exact date, and you will get news data that happened on that date.

Sort – You can utilize this parameter to specify sorting order. For example: by popularity.

Limit – Depending on your limit, you can specify a pagination limit, which is the number of results per page. The default value is 25, and the maximum allowed is 100. 

Make sure to check out the official documentation to learn about other functionalities and features of the MediaStack API.

Sample response data:

How to create a news web app with the MediaStack API using Node.js?

The engaging part is started! If you head over and check out the official documentation page, you find different sample apps with other technologies. In this demonstration, we will create a news web app using Node.js and other web technologies!

How to set up Node.js with MediaStack API?

Open your PowerShell or Bash if you are using Linux and type these commands to set up basic files of the project:

Now back to your terminal again and write these commands to install the required packages to our project. It installs Express, axios, body-parser, and EJS.

Now, create the folders and files that we need. As you can see, we have 3 different files in our CSS folder. But you should create, only the styles.scss file. After that, you need to install the Live Sass Compiler to compile our styles.scss file into styles.css file. It handles all the processes (You just need to click the Watch Sass button on the bottom of the VS Code after installation).

Now go back to your terminal and type this command :

And open your package.json configuration file and make these changes as it is:

Now, go back to your code editor and write this code!





Now we are good to go. Open your terminal and type this command to run the web app.

Here is our result:

Bonus Native Client Sample!

I hope you have enjoyed this real-world demonstration with Node.js. You can achieve more with Delphi FireMonkey and it can be faster.

Moreover, the FireMonkey Low-Code Wizard helps to create cross-platform fully-functional applications with several steps only. And you can connect to any RESTful web service with REST Debugger.

Furthermore, if you would like to parse only the needed values for your application you can utilize this function to get different data from the response easily.

The following code is for Embarcadero Delphi in Object Pascal.

Be sure to check Delphi Community Edition out here.

Head over and check out the full source code here: https://github.com/MuminjonGuru/News-Web-App-Using-Node.js-and-MediaStack-API

Are you ready to build apps using a quick and cost-effective JSON API for your news data requirements?

Ready to get started with MediaStack? Sign up!

Related posts

Location Based Services: Building with Ipstack


How to Use An API with Java


APILayer API Integration with Popular Frameworks


Building a Stock Market Dashboard Using Marketstack

Leave a Reply

Your email address will not be published. Required fields are marked *