Home > Mobile >  what is the difference between done and callback ? (Node.js)
what is the difference between done and callback ? (Node.js)

Time:08-22

What is the difference between a callback and done inside a function? I was using a package of passport google auth20, here return done(null, existingUser) is used. what is the main functionality or speciality of done? why not callback?

function(a, b, callback){
callback(something)
}

and

 async (request, accessToken, refreshToken, profile, done) => {
 try {
 let existingUser = await User.findOne({ 'google.id': profile.id });
 // if user exists return the user 
 if (existingUser) {
 return done(null, existingUser);
 }

CodePudding user response:

This is just an implementation detail. done is just a function that will be called, and is in theory a callback. Some developers choose to use a more meaningful parameter name instead of just callback.

  • Related