..:: Source code - fs-sync.js ::..

/*
This example shows synchronous execution, blocking code.
console.log(contents); blocks process and that's why
console.log('Do something else!'); must wait

Max file that didn't crash nodeJS had 350MB
 */

//load modules
var fs = require('fs');

//synchronous file reading
var content = fs.readFileSync('./testfiles/largefile350mb.txt', 'utf8');
console.log(content);

//here process is blocked while file is not read completely. After that next console.log(); continue

console.log('Do something else!');

/*
Conclusion: Due to asynchronous execution, first is file dumped then appear 'Do something else'.
That's because console.log('Do something else!'); waits fs.readFileSync('largefile350mb.txt', 'utf8'); to be finished.
 */
 

..:: NodeJS Console - fs-sync.js ::..

$ node fs-sync.js

		
		
$ps -aux | grep node (list all node processes)
sasa         849  0.5  0.5 1317632 86208 ?       Ssl  Oct08 282:50 node /home/sasa/regoch/regoch-www/server
sasa         880  0.4  0.5 1319240 88232 ?       Ssl  Oct08 235:30 node /home/sasa/dex8/dex8-www/server/index.js
sasa         890  0.5  0.5 11797800 84740 ?      Ssl  Oct08 334:08 node /home/sasa/mikosoft_hr/www-mikosoft-hr/server/index.js
sasa         903  0.7  0.4 1329652 81756 ?       Ssl  Oct08 430:34 node /home/sasa/mikosoft-info/api-mikosoft-info/starter.js
sasa         929  0.4  0.4 1300184 68836 ?       Ssl  Oct08 226:03 node /home/sasa/mikosoft-info/www-mikosoft-info/server/index.js
sasa         943  0.4  0.4 1300808 66520 ?       Ssl  Oct08 233:10 node /home/sasa/dex8/dex8-kiosk/server/index.js
sasa         980  0.6  0.5 11805104 92012 ?      Ssl  Oct08 364:20 node /home/sasa/mikosoft-info/dodo-mikosoft-info/server/index.js
sasa         981  0.7  0.6 1148036 104344 ?      Ssl  Oct08 394:42 node /home/sasa/voovuu/voovuu-api/starter.js
sasa        1039  0.9  1.4 11953364 245508 ?     Ssl  Oct08 554:47 node /home/sasa/voovuu/voovuu-pub/server/index.js
sasa     2044488  0.3  0.4 1298112 66796 ?       Ssl  Nov01  77:09 node /home/sasa/dex8/dex8-panel/server/index.js
sasa     2574087  0.3  0.4 11792920 77336 ?      Ssl  Nov08  41:43 node /home/sasa/@mikosoft/dodo-examples/server/index.js
sasa     2702010  0.4  0.6 22296952 100096 ?     Ssl  Nov10  34:52 node /home/sasa/dex8/dex8-worker/starter.js
sasa     2702011  0.3  0.4 1100276 66368 ?       Ssl  Nov10  31:02 node /home/sasa/dex8/dex8-worker/starter.js
sasa     2702018  0.3  0.3 1099884 65452 ?       Ssl  Nov10  31:05 node /home/sasa/dex8/dex8-worker/starter.js
sasa     2702019  0.3  0.4 1100516 66864 ?       Ssl  Nov10  31:03 node /home/sasa/dex8/dex8-worker/starter.js
sasa     2702046  0.9  0.7 22311780 123452 ?     Ssl  Nov10  84:08 node /home/sasa/dex8/dex8-worker/starter.js
sasa     2702047  0.3  0.3 1099492 65360 ?       Ssl  Nov10  31:20 node /home/sasa/dex8/dex8-worker/starter.js
sasa     2702088  0.3  0.3 1100008 65432 ?       Ssl  Nov10  31:05 node /home/sasa/dex8/dex8-worker/starter.js
sasa     2702089  0.3  0.4 1099752 66640 ?       Ssl  Nov10  31:01 node /home/sasa/dex8/dex8-worker/starter.js
sasa     2702137  0.3  0.4 1099864 65984 ?       Ssl  Nov10  30:52 node /home/sasa/dex8/dex8-worker/starter.js
sasa     2702139  0.4  0.6 22297196 101044 ?     Ssl  Nov10  35:23 node /home/sasa/dex8/dex8-worker/starter.js
sasa     3097623  1.1  0.8 11718784 131344 ?     Ssl  Nov13  43:48 node /home/sasa/dex8/dex8-api/starter.js
www-data 3362052  0.0  0.0   2608   596 ?        S    07:28   0:00 sh -c ps -aux | grep node
www-data 3362054  0.0  0.0   3304   732 ?        S    07:28   0:00 grep node