A node interface for NewsAPI.
Up-to-date news headlines and metadata in JSON from 70+ popular news sites. Powered by NewsAPI.org.
You will need an API key from https://newsapi.org.
Please look at their documentation to see how to use the API. The convenience functions provided by this module simply pass their options along as querystring parameters to the REST API, so the documentation is totally valid. There are some usage examples below to see how these options should be passed in.
If you use this in a project, add a 'powered by' attribution link back to NewsAPI.org
Add to your project
$ npm install newsapi --save
$ API_KEY=<your api key> npm test
Example usage of v2 API
All methods support promises and node-style callbacks.
const NewsAPI = ;const newsapi = 'YOUR_API_KEY';// To query top headlines// All options passed to topHeadlines are optional, but you need to include at least one of themnewsapiv2;// To query everything// You must include at least one q, source, or domainnewsapiv2;// To query sources// All options are optionalnewsapiv2;
Example usage of v1 legacy API
const NewsAPI = ;const newsapi = 'YOUR_API_KEY';// To query articles:newsapi;// To query sources:newsapi;// For both methods you can also use traditional Node callback style:newsapi;
NewsAPI's caching behavior.
You can disable caching on a request level by adding the
noCache: true option to your queries.