I use the following code and I need to convert it to promise and at the end return object which contain the file configuration, how should I do that ?
var Promise = require('bluebird'),
glob = promisifyAll(require("glob")),
fs = Promise.promisifyAll(require("fs"));
module.exports = {
parse: function (configErr) {
glob("folder/*.json", function (err, files) {
if (err) {
return configErr(new Error("Error to read json files: " + err));
}
files.forEach(function (file) {
fs.readFileAsync(file, 'utf8', function (err, data) { // Read each file
if (err) {
return configErr(new Error("Error to read config" + err));
}
return JSON.parse(data);
});
})
})
UPDATE -in the code I want to get json files from specific folder in my node project and parse the json content to object