Created
November 27, 2015 20:25
-
-
Save andrewjmead/f7800b972333dadfb3c5 to your computer and use it in GitHub Desktop.
Non-blocking vs blocking example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
fs.writeFileSync('message.txt', 'Hello Node.js'); | |
console.log('This will not print until the file is saved. Sync means do not use non-blocking.'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
fs.writeFile('message.txt', 'Hello Node.js', function (err) { | |
console.log('File is saved!'); | |
}); | |
console.log('This will fire before the file is saved because on non-blocking io'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment