通常の書き方

var fsObj = require(‘fs’);

fsObj.readFile(“demo.txt”,”utf-8″,function(err,data){
console.log(“here”);
});


fsObj.readFile(“demo2.txt”,”utf-8″,function(err,data){
console.log(“here2”);
});

console.log(“end”);

結果:

end

here

here2

asyncモジュールを利用する場合

参考URL: https://qiita.com/keneo/items/02421be10de13e92d6ad

var asyncObj = require(‘async’);

console.log(“– Series test start ———-“);
asyncObj.series([
function (callback) {
console.log(“1”);
setTimeout(function() {
console.log(“1 done”);
callback(null, 1);
}, 100);
},
function (callback) {
console.log(“2”);
setTimeout(function() {
console.log(“2 done”);
callback(“exit!”, 1);
}, 100);
},
], function (err, results) {
if (err) {
console.log(“err[” + err + “]”);
}
console.log(“- Series test done [” + results + “] ———-“);
});
console.log(“Series test end of line”);