How to let asynchronous readFile method follow order in node.js
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have a code like this var fs = require ( 'fs' ); console . log ( "1" ); fs . readFile ( "./index.js" , function ( err , data ) { if ( err ) { console . log ( "err" ); } console . log ( "2" ); }); console . log ( "3" ); and the result will be 1 3 2 But I want 1 2 3 I have look through filesystem's document and it says With the asynchronous methods there is no guaranteed ordering. so the document says if I want my code result 1 2 3 it should be var fs = require ( 'fs' ); console . log ( "1" ); fs . readFile ( "./index.js" ,