I wrote an example code following.
//test.js
var fs = require('fs');
fs.readdir(__dirname+'/app/img/', function(err, files) {
console.log(files);
});
someFunction(function(output){
console.log(output);
});
console.log('This is the final console call');
function someFunction(callback) {
callback(' I am some funciton. ');
}
Then, after runing 'node test.js', I got following result.
$ node test2.js
I am some funciton.
This is the final console call
[ 'photo1', 'photo2' ]
someFunction() is created by myself for simulating the callback function in fs.readdir(). And as my original assumption, the result should be
[ 'photo1', 'photo2' ]
I am some funciton.
This is the final console call
or
This is the final console call
[ 'photo1', 'photo2' ]
I am some funciton.
But now, logs of fs.readdir() and someFunction() appear before and after the log of final call log seperately.
hmmm.... I totally can't figure out it.
Therefore, my problem is that:
Why is the log from fs.readdir() is the last log?
Is it jsut because that fs.readdir() needs more time to execute?
Or, it's that I'm lack of some important concept about this issue?
Thanks you~!