javascript - Node.js, Mongodb, Monk, PapaParse, Bluebird, DB won't update -


so goal -> write script pull data out of csv , dump in database. seems working, except can't process exit without erasing whatever data (or not writing all) database.

db.then((db) => {     console.log('connected db');     const creators = db.get('creators');      let files = fs.readdirasync(folder)     .catch(err => {         exitonerr(err, 'error reading directory');     })     .map(filename => {         return processfile(filename)         .then(content => {             return papa.parsepromise(content);         })         .then(results => {             db_add(results, creators);         });     })     .then(() => {         console.log('completed parsing files..');         /* close db , exit process -> if here,            exits without doing anything, if            let process keep running, database            gets updated */     }); }).catch((err) => {     exitonerr(err, 'error connecting db'); }); 

where proper place close database , exit process? having trouble figuring out fit in scheme of promises here.

figured out. updated code:

db.then((db) => {     console.log('connected db');     const creators = db.get('creators');      return fs.readdirasync(folder)     .catch(err => {         exitonerr(err, 'error reading directory');     })     .map(filename => {         return processfile(filename)         .then(content => {             return papa.parsepromise(content);         })         .then(results => {             return db_add(results, creators);         });     }); }).catch((err) => {     exitonerr(err, 'error connecting db'); }).then(() => {     console.log('completed parsing files...');     closeandexit(0); }); 

wasn't returning promises chain.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

.htaccess - ERR_TOO_MANY_REDIRECTS htaccess -