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.
- use
fs promise module
instead, e.g., https://www.npmjs.com/package/fs-extra - use standard
fs
promisifyall
functionbluebird
library
Comments
Post a Comment