Skip to content Skip to sidebar Skip to footer

In Nodejs Access Variable Outside Callback Like Gloabal Varaible

var coll= ''; function test(callback){ MongoClient.connect(url, function(err, db) { if(err) throw err; coll=db callback(coll);

Solution 1:

You are not passing any callback function as argument to your test() function, therefore the statement in your test() function: callback(coll), will throw an error ending your script prior to calling console.log(coll).


Post a Comment for "In Nodejs Access Variable Outside Callback Like Gloabal Varaible"