-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
30 lines (26 loc) · 774 Bytes
/
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
var express = require("express");
var app = express();
var request = require("request");
app.set("view engine", "ejs");
app.get("/", function(req, res){
res.render("search");
});
app.get("/results", function(req, res){
var query = req.query.search;
var url = "http://omdbapi.com/?s=" + query + "&apikey=thewdb";
request(url, function(error, response, body){
if(!error && response.statusCode == 200) {
var data = JSON.parse(body)
res.render("results", {data: data});
}
else{
res.render("error");
}
});
});
const PORT = process.env.PORT || 3000;
const IP = process.env.IP || 'localhost';
app.listen(PORT, IP,
function(){
console.log("APP running at "+IP+":"+PORT);
});