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

Discussion (0)