Created
July 4, 2018 15:56
-
-
Save yukeehan/c2bf21ce1734ec5dde4808b033cf91c0 to your computer and use it in GitHub Desktop.
movie search app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.name; | |
var url = "http://www.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}); | |
} | |
}) | |
}); | |
app.listen(process.env.PORT, process.env.IP, function(){ | |
console.log("movie app is started!"); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>results page</h1> | |
<ul> | |
<% data["Search"].forEach(function(movie){ %> | |
<li> | |
<strong> | |
<%= movie.Title %> | |
</strong> | |
- <%= movie.Year %> | |
</li> | |
<% }); %> | |
</ul> | |
<button> | |
<a href="/"> | |
Search Again! | |
</a> | |
</button> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>this is the search page!</h1> | |
<form action="/results" method="GET"> | |
<input type="text" name="name" placeholder="movie"> | |
<button>Search!</button> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment