Based on a code snippet found here on stackoverflow, I want to read all files in a directory and then proceed. I've added a promise, but this somehow doesn't work.
My directory contains 2 files and the console log output is:
promise resolved
inside filenames
inside filenames
inside readFiles
inside readFiles 
function readFiles(dirname, onFileContent, onError) {
    return new Promise((resolve, reject) => {
        fs.readdir(dirname, function(err, filenames) {
            filenames.forEach(function(filename) {
                console.log('inside filenames');
                fs.readFile(dirname + filename, 'utf-8', function(err, content) {
                    onFileContent(filename, content);
                });
            });
        });
    });
}
var data = [];
readFiles('datadir/', function(filename, content) {
    console.log('inside readFiles');
    data.push(filename);
}).then(
    console.log('promise resolved');
    //proceed handling the data-array
);
 
    