Reputation: 145
I have got a code like
var dns = require('dns');
dns.resolve4('www.google.com', function (err, addresses) {
if (err) throw err;
console.log('addresses: ' + JSON.stringify(addresses));
});
How do we got the err, addresses arguments? what all other arguments can i pass? Thanks in advance.
Upvotes: 0
Views: 153
Reputation: 6232
Callback as for standard it takes the first argument as
error
and second argument asresult
Let's understand with simple example
/**
* [executeRequest description]
* @param {[type]} params [params which need to pass]
* @param {[type]} body [body which need to pass]
* @param {Function} callback [a callback function which finally executed after manipulation]
* @return {[type]} [callback with error or success]
*/
function executeRequest(params,body,callback){
//Execute some task here. it depends what this function does
pass error in callback if get error like this
callback(err);
pass result if success
callback(null,result);
}
Now call this function which needs to pass params, body and callback
executeRequest(params,body,function(err,result){
//Always the first argument of callback function is err and second argument is success
})
Upvotes: 1