javascript - How deep to nest promises and callbacks in NodeJS? -


only in context of promises , callbacks, following make sense?

static getdefaultadminheader(_this) {   return new promise((resolve, reject) => {     [nodejs fs module].readfile([name of file], (err, fd) => {       resolve(fd);     });  }); } 

in other words: promise above more add callback? or there programmatic plus structure?

from question,

promise can nested many layers want, code dirty.

usually, should not nested promise, or mixed promise , callback.

from code, there many solution remove callback.

  1. use fs promise module instead, e.g., https://www.npmjs.com/package/fs-extra
  2. use standard fs promisifyall function bluebird library

Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -