Juan Jo Juan Jo - 1 year ago 93
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")

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download