Node Js - Blocking and Non-Blocking Concept.
Look at these two blocks of code and find the difference. var fs = require ( "fs" ); var data = fs . readFileSync ( 'input.txt' ); console . log ( data . toString ()); console . log ( "Program Ended" ); var fs = require ( "fs" ); fs . readFile ( 'input.txt' , function ( err , data ) { if ( err ) return console . error ( err ); console . log ( data . toString ()); }); console . log ( "Program Ended" ); These two examples explain the concept of blocking and non-blocking calls. The first example shows that the program blocks until it reads the file and then only it proceeds to end the program. The second example shows that the program does not wait for file reading and proceeds to print "Program Ended" and at the same time, the program without blocking continues reading the file. Thus, a blocking program executes very much in sequence. From the programming point of view, it i...