DEV Community

Falah Al Fitri
Falah Al Fitri

Posted on

API newsapi.org | Express | for beginner

package.json

{
...
  "dependencies": {
    "express": "^4.17.1",
    "newsapi": "^2.4.1"
  }
}
Enter fullscreen mode Exit fullscreen mode

index.js

/* require newsapi */
const NewsAPI = require('newsapi');
const newsapi = new NewsAPI('YOUR-API-KEY');


/* require express */
const express   = require('express')
const app       = express()

app.get( "/", function( req, res ) {

    // To query sources
    // All options are optional
    newsapi.v2.sources().then( response => {

        console.log( response.sources )

    })

} )

app.listen(4000)
Enter fullscreen mode Exit fullscreen mode

References

npmjs.com/package/newsapi
npmjs.com/package/express

newsapi.org

Top comments (1)

Collapse
 
newsdataio profile image
Vineet Prasad

Hi there! I noticed that you're using Newsapi.org for your news data. Have you considered using NewsData.io news API? I've found it to be really comprehensive and easy to use. It might be worth checking out as an alternative for your news data needs. Good luck with your project