/* This example shows asynchronous execution, non-blocking code. console.log(contents); blocks process and that's why console.log('Do something else!'); must wait Successfully loads files up to 1000MB. */ //load modules var fs = require('fs'); //asynchronous file reading fs.readFile('./testfiles/largefile1000mb.txt', function(err, content){ console.log(content); }); //here process is not blocked. While file is loading the next console.log(); continue with execution console.log('Do something else!'); /* Conclusion: Due to asynchronous execution, first appear 'Do something else' then is file dumped. */
Do something else! undefined
$ps -aux | grep node (list all node processes) sasa 849 0.5 0.5 1317376 86148 ? Ssl Oct08 282:48 node /home/sasa/regoch/regoch-www/server sasa 880 0.4 0.5 1319240 88056 ? Ssl Oct08 235:29 node /home/sasa/dex8/dex8-www/server/index.js sasa 890 0.5 0.5 11797800 84868 ? Ssl Oct08 334:06 node /home/sasa/mikosoft_hr/www-mikosoft-hr/server/index.js sasa 903 0.7 0.4 1329652 81528 ? Ssl Oct08 430:31 node /home/sasa/mikosoft-info/api-mikosoft-info/starter.js sasa 929 0.4 0.4 1300184 68392 ? Ssl Oct08 226:02 node /home/sasa/mikosoft-info/www-mikosoft-info/server/index.js sasa 943 0.4 0.4 1300808 66368 ? Ssl Oct08 233:09 node /home/sasa/dex8/dex8-kiosk/server/index.js sasa 980 0.6 0.5 11805104 92548 ? Ssl Oct08 364:18 node /home/sasa/mikosoft-info/dodo-mikosoft-info/server/index.js sasa 981 0.7 0.6 1148036 104268 ? Ssl Oct08 394:40 node /home/sasa/voovuu/voovuu-api/starter.js sasa 1039 0.9 1.4 11942148 241800 ? Ssl Oct08 554:43 node /home/sasa/voovuu/voovuu-pub/server/index.js sasa 2044488 0.3 0.4 1298112 66756 ? Ssl Nov01 77:07 node /home/sasa/dex8/dex8-panel/server/index.js sasa 2574087 0.3 0.4 11792920 77324 ? Ssl Nov08 41:42 node /home/sasa/@mikosoft/dodo-examples/server/index.js sasa 2702010 0.4 0.6 22296952 100228 ? Ssl Nov10 34:50 node /home/sasa/dex8/dex8-worker/starter.js sasa 2702011 0.3 0.4 1100276 66128 ? Ssl Nov10 31:00 node /home/sasa/dex8/dex8-worker/starter.js sasa 2702018 0.3 0.3 1099884 64812 ? Ssl Nov10 31:03 node /home/sasa/dex8/dex8-worker/starter.js sasa 2702019 0.3 0.4 1100516 67296 ? Ssl Nov10 31:02 node /home/sasa/dex8/dex8-worker/starter.js sasa 2702046 0.9 0.7 22311780 124424 ? Ssl Nov10 84:07 node /home/sasa/dex8/dex8-worker/starter.js sasa 2702047 0.3 0.3 1099492 65412 ? Ssl Nov10 31:19 node /home/sasa/dex8/dex8-worker/starter.js sasa 2702088 0.3 0.4 1100008 66436 ? Ssl Nov10 31:03 node /home/sasa/dex8/dex8-worker/starter.js sasa 2702089 0.3 0.4 1099752 65956 ? Ssl Nov10 30:59 node /home/sasa/dex8/dex8-worker/starter.js sasa 2702137 0.3 0.4 1099864 65844 ? Ssl Nov10 30:51 node /home/sasa/dex8/dex8-worker/starter.js sasa 2702139 0.4 0.6 22297196 101820 ? Ssl Nov10 35:21 node /home/sasa/dex8/dex8-worker/starter.js sasa 3097623 1.1 0.8 11718784 131576 ? Ssl Nov13 43:46 node /home/sasa/dex8/dex8-api/starter.js www-data 3361584 0.0 0.0 2608 608 ? S 07:21 0:00 sh -c ps -aux | grep node www-data 3361586 0.0 0.0 3304 732 ? S 07:21 0:00 grep node