Skip to content

Instantly share code, notes, and snippets.

@rootid
Last active August 29, 2015 14:22
Show Gist options
  • Save rootid/0d4736fa3a4d2aae9040 to your computer and use it in GitHub Desktop.
Save rootid/0d4736fa3a4d2aae9040 to your computer and use it in GitHub Desktop.
//sync v/s async
//Count # of lines
var fs = require('fs')
var fileName = process.argv[2]
//Async call
fs.readFile(fileName,function (err, data) {
lst_ = data.toString();
console.log(lst_.split('\n').length - 1);
});
//Sync call
buffer_ = fs.readFileSync(fileName);
len_ = buffer_.toString().split('\n').length - 1;
console.log(len_)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment