I am using npm Express and Request modules to obtain movie information via an API:
var express = require("express");
var app = express();
var request = require("request");
app.get("/results", function(req, res){
console.log(getBody("http://www.omdbapi.com/?s=The+Shining&page=1&apikey=myKey"));
});
function getBody(requestString){
request(requestString, function(error, response, body){
return body;
};
}
I removed error checking on the request here for the sake of readability.
Within the request, logging "body" shows that the request did return proper JSON. However, when I return to app.get, the value of the logging is undefined.
Is it not possible to return this value to app.get's callback function?