Skip to content

Instantly share code, notes, and snippets.

@yukeehan
Created July 4, 2018 15:56
Show Gist options
  • Save yukeehan/c2bf21ce1734ec5dde4808b033cf91c0 to your computer and use it in GitHub Desktop.
Save yukeehan/c2bf21ce1734ec5dde4808b033cf91c0 to your computer and use it in GitHub Desktop.
movie search app
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!");
});
<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>
<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