Skip to content

Instantly share code, notes, and snippets.

@andrewjmead
Created November 27, 2015 20:25
Show Gist options
  • Save andrewjmead/f7800b972333dadfb3c5 to your computer and use it in GitHub Desktop.
Save andrewjmead/f7800b972333dadfb3c5 to your computer and use it in GitHub Desktop.
Non-blocking vs blocking example
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.');
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