Juan Jo Juan Jo - 4 months ago 47
Node.js Question

Node Server return Promise

I am a beginner and can hardly understand promises or callbacks,how can I return the data below so my home server can respond to requests
thanks for any help

else if(requests["mode"]==="onlineVideoQuery"){
var title = requests["title"].replace(/\+/g," ")

imdb.get(title).then(function(data) {
//I need to get this data above for response.end(data)

response.end("how can I return the data above to this response")


You can call the response.end in the then function:

else if (requests["mode"] === "onlineVideoQuery") {
  var title = requests["title"].replace(/\+/g, " ")

  imdb.get(title).then(function(data) {

Make sure call response.end once por request, and to don't mix async code with sync code, that could generate a race condition.