npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

news-wrapper

v2.0.0

Published

A Javascript library to work with API news

Readme

news-wrapper

Build Status

[WIP] A Javascript wrapper to work with [News API] (https://newsapi.org).

Installation

$ npm install --save news-wrapper

How to use

ES6

// to import a specific method
import NewsWrapper from 'news-wrapper';

const news = new NewsWrapper({
  token: 'YOUR_TOKEN_HERE'
});

// using  method
const promise = news.search.topheadlines({ sources: 'cnn'});
promise.then(({ data }) => {
  const markup = data.articles.map(headline => {
    return `<div>${headline.title}</div>`;
  });

  document.getElementById('news').innerHTML = markup;
});

CommonJS

const NewsWrapper = require('news-wrapper').default;

const news = new NewsWrapper({
  token: 'YOUR_TOKEN_HERE'
});

UMD in Browser

<!-- to import non-minified version -->
<script src="news-wrapper.umd.js"></script>

<!-- to import minified version -->
<script src="news-wrapper.umd.min.js"></script>

After that the library will be available to the Global as NewsWrapper. Follow an example:


const news = new NewsWrapper({
  token: 'YOUR_TOKEN_HERE'
});

const sources = news.search.sources({ category: 'technology'});

Methods

Follow the methods that the library provides.

search.topheadlines(query)

This method provides live top and breaking headlines for a single source, or multiple sources. Test in npm runkit.

Arguments

| Argument | Type | Options | |-----------|---------|---------------------| |query |string | 'Any search query' | |sources |string | 'Any source query' | |category |string | 'Any category query'| |language |string | 'Any language' | |country |string | 'Any country' |

The argument query is optional. In case nothing is passed, the method will retrieve Techcrunch available headlines. In case more than one source is needed, you can add a string separated by commas, like 'cnn,techcrunch,bbc' for example.

Default: Techcrunch.

For more details about country and language supported, please check NewsAPI

Example

news.search.topheadlines({ sources: 'cnn'});
  .then(({ data }) => {
    // do what you want with the data
  })

If you want to specify more than one source:

news.search.topheadlines({ sources: 'cnn,techcrunch,bbc' });
  .then(({ data }) => {
    // do what you want with the data
  })

search.sources(query)

This method will get all sources available. It's possible to filter by either category and/or country. Test in npm runkit.

Arguments

| Argument | Type | Options | |------------|---------|------------------------| |category |string | 'Any of the below list'| |country |string | 'Any of the below list'| |language |string | 'Any of the below list'|

  • Available categories: business entertainment gaming general health-and-medical music politics science-and-nature sport technology Default: all categories.

  • Available countries: ar au br ca cn de es fr gb hk ie in is it nl no pk ru sa sv us za Default: all countries.

  • Available languages: ar en cn de es fr he it nl no pt ru sv ud Default: all languages.

Example

news.search.sources({ category: 'technology', country: 'us' })
  .then(({ data } ) => {
    // do what you want with the data
  })

search.everything(query)

This method retrieves all news related to the query passed in. It includes all kind of sources. Test in npm runkit.

Arguments

| Argument | Type | Options | |-----------|---------|---------------------| |query |string | 'Any search query' | |sources |string | 'Any source query' | |from |string | 'Starting date' | |to |string | 'Ending date' | |page |int | 'Pagination number' |

The only required parameter is query, all other parameters are optional. Both from and to needs to be in ISO 8601 format (e.g. 2018-01-02 or 2018-01-02T12:16:22)

  • Default page: 1

Example

news.search.everything({ query: 'bitcoin' })
  .then(({ data }) => {
    // do what you want with the data
  })
news.search.everything({ query: 'bitcoin', sources: 'cnn', from: '2017-12-23', to: '2017-12-28', page: 2 })
  .then(({ data }) => {
    // do what you want with the data
  })

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

License

This project is licensed under the ISC License - see the LICENSE.md file for details