-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
117 lines (94 loc) · 2.44 KB
/
app.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
const express = require('express');
const request = require('request');
const bodyParser = require('body-parser');
const { getChart } = require('billboard-top-100');
const giveMeAJoke = require('give-me-a-joke');
const app=express();
app.use(express.static("public"));
app.use(bodyParser.urlencoded({extended: true}));
app.set("view engine", "ejs");
app.get("/",function(req,res){
res.render("landing");
});
// app.get("/",function(req,res){
// res.render("landing");
// });
app.post("/home",function(req,res){
res.render("home");
});
var word,val1;
app.post("/dic",function(req,res){
res.render("dicindex");
});
app.post("/find",function(req,res){
word=req.body.word;
// console.log(word);
let url="https://www.dictionaryapi.com/api/v3/references/collegiate/json/" + word + "?key="+"1f1f3a1c-0d7a-441c-a5a0-46094d35f54a";
request(url,function(err,res1,body){
// console.log(res1.body);
val1 = JSON.parse(res1.body);
console.log(val1);
if(val1[0] == undefined)
{
res.render("failure");
}
else if(val1[0].meta == undefined)
{
res.render("failure");
}
else{
res.render("find",{
searched: word,
received: val1
});
}
});
});
var d = new Date();
var pastDate = d.getDate() - 7;
d.setDate(pastDate);
month = '' + (d.getMonth() + 1),
day = '' + d.getDate(),
year = d.getFullYear();
if (month.length < 2)
month = '0' + month;
if (day.length < 2)
day = '0' + day;
var l= year+'-'+month+'-'+day;
app.post("/bill",function(req,res){
getChart('hot-100',l, (err, chart) => {
if (err) console.log(err);
else
{
res.render("bill",{
data: chart
});
}
});
});
app.post("/joke",function(req,res){
giveMeAJoke.getRandomDadJoke (function(joke) {
res.render("joke",{
joke: joke
});
});
});
app.post("/game",function(req,res){
res.render("game");
});
app.post("/news",function(req,res){
var url ='http://newsapi.org/v2/top-headlines?' +
'country=in&' +
'apiKey=6438b2fa356d49578b3807911f13dded';
request(url,function(err,res1,body){
var val=JSON.parse(res1.body);
console.log(val);
res.render("news",{
headlines: val
});
});
});
app.listen(process.env.PORT || 3000,function(){
console.log("Listening at port 3000");
})
// 6438b2fa356d49578b3807911f13dded