Detail of error on execution:
# node app.jsthrow new TypeError('callback provided to sync glob')
^
TypeError: callback provided to sync glob
at glob (C:\Users\z\Documents\node_modules\glob\glob.js:70:13)
at Object.module.exports.getGlobbedFiles (C:\Users\z\Documents\Server\Config\config.js:31:4)
at Object.<anonymous> (C:\Users\z\Documents\Server\app.js:102:10)
I'm using glob 5.0.14 to start meanjs app.
This is my config.js:
var _ = require('lodash'),
glob = require('glob');
module.exports.getGlobbedFiles = function(globPatterns, removeRoot) {
var _this = this;
var urlRegex = new RegExp('^(?:[a-z]+:)?\/\/', 'i');
var output = [];
if (_.isArray(globPatterns)) {
globPatterns.forEach(function(globPattern) {
output = _.union(output, _this.getGlobbedFiles(globPattern, removeRoot));
});
} else if (_.isString(globPatterns)) {
if (urlRegex.test(globPatterns)) {
output.push(globPatterns);
} else {
31=> glob(globPatterns, {
sync: true
}, function(err, files) {
if (removeRoot) {
files = files.map(function(file) {
return file.replace(removeRoot, '');
});
}
output = _.union(output, files);
});
}
}
return output;
};
And app.js line 102:
config.getGlobbedFiles('./Rutas/*.js').forEach(function(routePath) {
require(path.resolve(routePath))(app);
});
Like I said, you are passing callback parameter to a synchrounous call, change it to either work async or, remove the callback parameter:
...
else {
var files = glob(globPatterns, { sync: true });
if (removeRoot) {
files = files.map(function(file) {
return file.replace(removeRoot, '');
});
}
output = _.union(output, files);
}
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With