Wednesday, 10 May 2017

module exports async function keep on the same file

Hello I have two files: "mongo-update" file to update a document in mongo db which calls a function from the second file "job.js", after the document is updated. The thing is that once that I'm executing the function of the "job" file I want to stick on that file and don't go back again to mongo-update file. However I'm missing something...

This is my mongo-update file

return new Promise((resolve, rej)=>{
      MongoClient.connect(mongourl, function(err, db) {

                        db.collection("books").update({"_id" : objectId(mongoId._id.toHexString())}, {$set: {"book": mainUrl}})
                        .then((res) => {
                          resolve(mainUrl);
                        });                        
        } );
 })
.then((url) => {
   return job.getSavedUrlPromise(url)
})
.then((promise) => {
    console.log("inside here again!!!!! :(  ")
    console.log(promise)
});
      

And this is my job.js file:

var getUrl;

module.exports={
    
  getSavedUrlPromise(url){
      getUrl = url;
      
      
      return JobModuleExportsPromise(getUrl)
  
  
    
  }

}


function JobModuleExportsPromise(url){
    console.log("inside JobModuleExportsPromise")
    console.log(url)
}

How can I avoid going back again to the "mongo-update" file and keep on going from the job file?



via Defoe

No comments:

Post a Comment