Thursday, 11 May 2017

How do i nest a promise inside another promise function in node.js?

js file which is surrounded by Promise function . I have a database operation inside this function which requires another promise too . Please check the code below

var ted = dep.map(function(name){

return new Promise(function(resolve,reject){ 
    /*..list of other tasks*/
    for(int i = 0 ;i<3<;i++){        
    savetomongodb(param1,param2),// this is async function
   } 
    resolve();

    )};

Now i have to export this module to a different file

Im using the below code

module.exports = Promise.all(ted,savemongo);

How do I wait till my savetomongodb function is complete .



via karthik006

No comments:

Post a Comment