-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
61 lines (37 loc) · 1.37 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
var express = require("express");
var app = express();
var request = require("request");
var bodyParser = require("body-parser");
app.use(express.static("public"));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.set("view engine", "ejs");
app.get("/", function(req, res) {
res.render("search");
});
app.get("/results", function(req, res) {
var query = req.query.city;
var url = "https://api.weatherbit.io/v2.0/current?city=" + query + "&key=8d05c53189244c0e8bf497c3ff8d1494";
// var url2 = "https://api.weatherbit.io/v2.0/alerts?city=" + query + "&key=8d05c53189244c0e8bf497c3ff8d1494";
request(url, function(err, response, body) {
if (!err && response.statusCode == 200) {
var results = JSON.parse(body);
console.log(results);
res.render("result", data = results);
}
});
});
app.get("/movie", function(req, res) {
var query = req.query.moviename;
var url = "http://www.omdbapi.com/?s=" + query + "&apikey=thewdb"
request(url, function(error, response, body) {
if (!error && response.statusCode == 200) {
var movie = JSON.parse(body)
res.render("movie", data = movie);
// res.send(results["Search"][0]["Title"]);
}
});
});
app.listen(3000, function() {
console.log("Weather API started");
});