Welcome to the world !!!!!!
Let's get married
Create a file named input.txt with the following content:
QTM la trang Web huong dan cac bai lap trinh hoan toan mien phi cho tat ca moi nguoi !!!!!
Update main.js with the following code:
var fs = require ( "fs" ); fs . readFile ( 'input.txt' , function ( err , data ) { if ( err ) return console . error ( err ); console . log ( data . toString ()); }); console . log ( "Ket process" );
Now run main.js to see the result:
$ node main . js
Result:
Let's get married
QTM is a Web page that contains all the scripts
Welcome to the world !!!!!!
These two examples explain the definition of blocking and non-blocking calls. The first example shows that the program locks until it reads the file and continues to run only a few seconds later, the second program does not wait for the file to read and continues to print "Ket" after the same time. show program.
According to Tutorialspoint
Previous article: NPM in Node.js
Next: Event Loop in Node.js