-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
51 lines (50 loc) · 1.7 KB
/
index.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
const express = require('express');
const app = express();
const googleTrends = require('google-trends-api');
const dayjs = require('dayjs');
const cors = require('cors');
app.use(cors());
app.get('/pastmonth', (req, res) => {
new Promise((resolve,reject)=>{
googleTrends.interestOverTime({keyword: req.query.keyword,startTime : dayjs().subtract(1, 'month').toDate()})
.then(function(result){
let trendResult = JSON.parse(result)
resolve(trendResult)
})
.catch(function(err){
console.error('Oh no there was an error', err);
});
}).then((result)=>{
res.json(result)
})
});
app.get('/pasthalfyear', (req, res) => {
new Promise((resolve,reject)=>{
googleTrends.interestOverTime({keyword: req.query.keyword,startTime : dayjs().subtract(6, 'month').toDate()})
.then(function(result){
let trendResult = JSON.parse(result)
resolve(trendResult)
})
.catch(function(err){
console.error('Oh no there was an error', err);
});
}).then((result)=>{
res.json(result)
})
});
app.get('/pastyear', (req, res) => {
new Promise((resolve,reject)=>{
googleTrends.interestOverTime({keyword: req.query.keyword,startTime : dayjs().subtract(1, 'year').toDate()})
.then(function(result){
let trendResult = JSON.parse(result)
resolve(trendResult)
})
.catch(function(err){
console.error('Oh no there was an error', err);
});
}).then((result)=>{
res.json(result)
})
});
var port = process.env.PORT || 3000;
app.listen(port, () => console.log(`Example app listening on port ${port}`));