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

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -