I don't understand, why in the below code glob()
internal function don't executes immideately.
'use strict';
const glob = require('glob');
function testFunction(){
console.log('Checkpoint 1');
let objectWillBeFilled = {};
glob(/* GlobPattern */, (errors, files) => {
console.log('Checkpoint 2');
files.forEach( (value, index, array) => {
// do something ...
// adding some key-value pairs to objectWillBeFilled ...
console.log('Checkpoint 3');
});
});
console.log('Checkpoint 4');
return objectWillBeFilled;
}
testFunction();
I get the next sequence of the logs to console:
- Checkpoint 1
- Checkpoint 4
- Checkpoint 2
- Checkpoint 3
So, the testFunction
returns the empty objectWillBeFilled
.
What I missed in JavaScript/Node JS learning?