news-api-njs
An interface for Node and the newsapi.org API
You'll need an API key from News API
You can install using npm install --save news-api-njs
Then you can set up like so, where username is a default username:
var NewsApi = require('news-api-njs'),
config = require('./config');
var news = new NewsApi({
apiKey: config.apiKey
});
After this, you can use either of the following methods
Get Sources
getSources(opt);
Returns all possible sources
where
opt = {
category: category
language: top|latest|popular
callback(res) {}
}
and callback is a function which receives a single object, containing the News API response and success: true|false
Get Articles
Returns list of articles from a given source
getArticles(opt);
opt = {
category: business|entertainment|gaming|general|music|science-and-nature|sport|technology
language: en|de|fr
country: au|de|gb|in|it|us
callback(res) {}
}
and callback is a function which receives a single object, containing the News API response and success: true|false
Alternately, you can use JavaScript promises like so
news.getArticles({
source: 'ars-technica',
sortBy: 'latest'
}).then(function(res) {
console.log(res);
}).catch(function(err) {
console.log(err);
});
You can read a full description of what options do and what the response looks like at newsapi.org, or view examples