
Security News
Open Source Maintainers Feeling the Weight of the EU’s Cyber Resilience Act
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.
newsapi-wrapper
Advanced tools
A wrapper around the News API (https://newsapi.org/) that exposes a Promise-like interface
newsapi-wrapper is a convenient wrapper to call the News API. All you will need is an API key that you can get here.
const newsapi = require('newsapi-wrapper');
newsapi
.setApiKey('xxxxyyyzzz')
.setCountry('ca')
.setCategory('sports')
.setPageSize(25)
.send()
.then(response => {
console.log(`Results: ${response.totalResults}`);
response.articles.forEach(article => {
console.log(article.title);
});
})
.catch(err => {
console.log(err);
});
npm install newsapi-wrapper
yarn add newsapi-wrapper
Sets a single default value. Possible keys: country, category, apiKey, pageSize
newsapi.setDefault('country', 'de');
Sets multiple default values at once. Takes an object as a parameter. Possible keys: country, category, apiKey, pageSize.
newsapi.setDefaults({
country: 'de',
pageSize: 10,
category: 'sports'
});
Returns an array containing all valid categories, which are: business, entertainment, general, health, science, sports, technology
Sets the news category for the next request (not for all subsequent requests). Returns a Request object that can be used to chain other method calls, or to send the request.
const request = newsapi.setCategory('health');
request.setCountry('uk').send();
Sets the country for the next request (not for all subsequent requests). Returns a Request object that can be used to chain other method calls, or to send the request.
Sets the page size for the next request (not for all subsequent requests). Returns a Request object that can be used to chain other method calls, or to send the request.
Sets the NewsAPI key for the next request (not for all subsequent requests). Returns a Request object that can be used to chain other method calls, or to send the request.
The call to send
returns a promise which resolves when the response from the News API is received as intended. Otherwise, it is rejected:
newsapi.request()
.setCategory('health')
.setPageSize(15)
.send()
.then(response => {
// Probably do something with response.articles
})
.catch(err => {
console.log(err);
});
Returns an object you can use to build a request, send it, and process the result. Intended to used as a chain of method calls:
newsapi.request()
.setCategory('health')
.setPageSize(15)
.send();
request() is now optional and considered deprecated, because you can call all the request methods on newsapi directly. The above example would then look like this:
newsapi.setCategory('health')
.setPageSize(15)
.send();
FAQs
A wrapper around the News API (https://newsapi.org/) that exposes a Promise-like interface
The npm package newsapi-wrapper receives a total of 6 weekly downloads. As such, newsapi-wrapper popularity was classified as not popular.
We found that newsapi-wrapper demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.