ES5 Promise Example
Simple example of how to create an ES5 Promise.
// A. If no dirPath exists, use a default.
var dirPath = (dirPath) ? dirPath: `${process.cwd()}/html/raw/`;
let promise = await new Promise( async (resolve, reject) => {
// B. Prepend absolute directory path to the beginning of each array element
let array = fs.readdirSync(dirPath).map(filePaths => { return `${dirPath}${filePaths}` })
// C. Remove hidden files
.filter(Utils.isNotUnixHiddenPath)
// D. Remove directories and other non-files.
.filter(Utils.isFile)
// E. Success
resolve( array );
})
.then( response => { return response } )
.catch( err => console.error(err) );
return promise;