Manas S. Roy
Manas S. Roy

Reputation: 333

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

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);
 }

Upvotes: 0

Views: 69

Answers (1)

Titulum
Titulum

Reputation: 11486

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.

Upvotes: 1

Related Questions