Toggle navigation
Genres
Frontend (2)
JavaScript (6)
Database (2)
Linux Server (3)
Web Apps (4)
Misc (4)
Search
List
New Tutorials
Last Modified Tutorials
</>
Code examples
code
smiko
javascript
nodejs
fs-async.js
fs-async.js
/* 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. */
Reload page
Preview
W3C validation
Edit Code
JS Console