0.2.1 • Published 9 years ago
news-api-njs v0.2.1
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 // optional
        language: top|latest|popular //optional, default is top
        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 //opt, default is all
        language: en|de|fr //opt, default is all
        country: au|de|gb|in|it|us //opt, default is all
        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