callback in response node js

Solutions on MaxInterview for callback in response node js by the best coders in the world

showing results for - "callback in response node js"
Lya
18 Oct 2016
1//you can only return a value from an async function by passing in a callback function like so: 
2function longRunningFunction(param1, callback){
3    setTimeout(function(){
4         var results="O High there!";
5         callback(results);
6    }, 2000);
7} 
8
9//then call the async function and pass the callback function like so
10longRunningFunction("morning", function(result){
11  alert(result);
12});