How do I control my callbacks in Node.js? -


so i'm working on application written in coffeescript , i'm using sequelize orm application. i'm @ stage i'm integrating passport.js. part i'm having issues getting user out of database when trying authenticate. know issue function returning before sequelize function have written has had chance return can't figure out how control flow properly.

here code i've got far: user model

exports.getuserbyusername = (username, callback) -> user.findone({     : {      username : username     }}, (err, user) ->     console.log 'hello?'     return callback(err) if err     return callback(undefined, user) if user ) 

hello doesn't called that's step 1 of knowing it's returning soon. in verification callback inside passport strategy have this:

(username, password, done) ->     chatmodel.getuserbyusername username, (err, user) ->         console.log 2         return done err if err         return done null, false, message: 'incorrect user' if not user          if chatmodel.isvalidpassword user, password return done null, user     console.log 1 

again, "1" logged console , "2" never logged must mean it's returning. can tell me how should controlling flow of execution?

thank in advance if can help.


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -