🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

news-api-njs

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

news-api-njs

A Node app that hooks into newsapi.org

0.2.1
latest
Source
npm
Version published
Weekly downloads
7
600%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

news

FAQs

Package last updated on 07 Oct 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts