-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
34 lines (26 loc) · 767 Bytes
/
app.js
File metadata and controls
34 lines (26 loc) · 767 Bytes
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
var express = require('express');
var request = require('request')
var app = express();
app.set('view engine','ejs');
app.use(express.static("public"))
app.get('/',(req,res) =>{
res.render('search');
})
app.get('/results', (req,res) =>{
var query = req.query.search;
var url = `http://www.omdbapi.com/?apikey=2c6e7a77&s=${query}`;
if (query === ""){
res.render("error")
}
else{
request(url,(error,response,body) =>{
if(!error && response.statusCode === 200){
var parsedData = JSON.parse(body);
res.render('results', {data: parsedData})
}
})
}
})
app.listen(process.env.PORT,() =>{
console.log("Server Listening on port 3000");
})