-
Notifications
You must be signed in to change notification settings - Fork 0
/
news.js
52 lines (50 loc) · 918 Bytes
/
news.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const NewsAPI = require('newsapi');
const newsapi = new NewsAPI('0b897ecb342e419baac8c0c06503f9eb');
newsapi.v2.topHeadlines({
// sources: 'bbc-news,the-verge',
q: 'bitcoin',
category: 'business',
language: 'en',
country: 'us'
}).then(response => {
console.log(response);
/*
{
status: "ok",
articles: [...]
}
*/
});
newsapi.v2.everything({
q: 'bitcoin',
sources: 'bbc-news,the-verge',
domains: 'bbc.co.uk, techcrunch.com',
from: '2023-010-25',
to: '2023-10-26',
language: 'en',
sortBy: 'relevancy',
page: 2
}).then(response => {
console.log(response);
/*
{
status: "ok",
articles: [...]
}
*/
});
// To query sources
// All options are optional
newsapi.v2.sources({
category: 'technology',
language: 'en',
country: 'us'
}).then(response => {
console.log(response);
/*
{
status: "ok",
sources: [...]
}
*/
});