How callback use in this case

26 views
Skip to first unread message

Manpreet Gill

unread,
Mar 4, 2016, 10:28:01 PM3/4/16
to nodejs
this file is example.js:= module.exports = {
dashboarddistance: function(a, b, c, d, callback) {
var ds = 0;
var distance = require('google-distance');
distance.get({
index: 1,
origin: a + ',' + b,
destination: c + ',' + d
}, function(err, data) {
if (err) {
console.log("a");
ds = 0;
return callback(err, ds);
} else {
console.log("b");
ds = data.distance;
return callback(null, ds);
}
});
},
}; main.js file this :=
var example = require('./example.js');
example.dashboarddistance(a, b, c, d, function(err, distance) {
if (err) {
// dosomething and return
return ;
}
console.log(distance);
});

Ryan Schmidt

unread,
Mar 5, 2016, 11:52:00 AM3/5/16
to nod...@googlegroups.com
I would put


var distance = require('google-distance');


outside of the function, outside of the module.exports object.

Other than that, what's your question about this code?



Reply all
Reply to author
Forward
0 new messages