/*
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.readFile('./testfiles/largefile350mb.txt', 'utf8');
console.log(content); //returns 'undefined' because readFile requires callback and dont return any value
//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.
*/
$ps -aux | grep node (list all node processes) sasa 1194 0.5 0.4 1303236 79688 ? Ssl Oct24 275:00 node /home/sasa/.pm2/modules/pm2-logrotate/node_modules/pm2-logr sasa 1200 0.9 0.8 11722864 138916 ? Ssl Oct24 482:37 node /home/sasa/dex8/dex8-api/starter.js sasa 1207 0.4 0.4 1305676 73992 ? Ssl Oct24 226:44 node /home/sasa/regoch/regoch-www/server sasa 1208 0.3 0.4 1304912 72900 ? Ssl Oct24 197:11 node /home/sasa/dex8/dex8-panel/server/index.js sasa 1224 0.8 0.6 11822116 99960 ? Ssl Oct24 474:57 node /home/sasa/dex8/dex8-www/server/index.js sasa 1236 0.5 0.5 11813132 97292 ? Ssl Oct24 302:01 node /home/sasa/mikosoft_hr/www-mikosoft-hr/server/index.js sasa 1255 0.7 0.5 1330860 83704 ? Ssl Oct24 404:51 node /home/sasa/mikosoft-info/api-mikosoft-info/starter.js sasa 1257 0.3 0.4 1301028 69756 ? Ssl Oct24 200:24 node /home/sasa/mikosoft-info/www-mikosoft-info/server/index.js sasa 1289 0.3 0.4 1297724 67608 ? Ssl Oct24 197:38 node /home/sasa/dex8/dex8-kiosk/server/index.js sasa 1363 3.1 2.8 12158260 462432 ? Ssl Oct24 1687:37 node /home/sasa/voovuu/voovuu-pub/server/index.js sasa 1449 0.3 0.4 1168360 65812 ? Ssl Oct24 207:08 node /home/sasa/dex8/dex8-worker/starter.js sasa 1528 1.7 2.7 33111048 449256 ? Ssl Oct24 920:56 node /home/sasa/dex8/dex8-worker/starter.js sasa 1529 0.3 0.3 1100900 64428 ? Ssl Oct24 206:56 node /home/sasa/dex8/dex8-worker/starter.js sasa 1606 0.3 0.3 1100644 64484 ? Ssl Oct24 207:00 node /home/sasa/dex8/dex8-worker/starter.js sasa 1607 0.3 0.4 1101156 66060 ? Ssl Oct24 206:23 node /home/sasa/dex8/dex8-worker/starter.js sasa 1705 0.3 0.4 1101416 65884 ? Ssl Oct24 206:20 node /home/sasa/dex8/dex8-worker/starter.js sasa 1706 0.3 0.3 1101156 65356 ? Ssl Oct24 206:13 node /home/sasa/dex8/dex8-worker/starter.js sasa 1805 0.3 0.4 1166944 66088 ? Ssl Oct24 206:28 node /home/sasa/dex8/dex8-worker/starter.js sasa 1807 0.3 0.3 1100128 63880 ? Ssl Oct24 202:18 node /home/sasa/dex8/dex8-worker/starter.js sasa 1885 0.3 0.3 1099880 63340 ? Ssl Oct24 203:38 node /home/sasa/dex8/dex8-worker/starter.js sasa 1886 1.6 0.9 11859024 162168 ? Ssl Oct24 887:51 node /home/sasa/mikosoft-info/crypto-mikosoft-info/server/index. sasa 2628167 0.8 0.7 1170728 127364 ? Ssl Nov04 306:41 node /home/sasa/voovuu/voovuu-api/starter.js sasa 3168557 0.6 0.5 11800780 90080 ? Ssl Nov06 218:18 node /home/sasa/mikosoft-info/dodo-mikosoft-info/server/index.js sasa 3169051 0.4 0.5 11798408 83192 ? Ssl Nov06 142:35 node /home/sasa/@mikosoft/dodo-examples/server/index.js www-data 3875540 0.0 0.0 2608 528 ? S 07:21 0:00 sh -c ps -aux | grep node www-data 3875542 0.0 0.0 3304 660 ? S 07:21 0:00 grep node