Created
December 5, 2015 19:40
-
-
Save tanyagupta/d5f80b316102ffdc3251 to your computer and use it in GitHub Desktop.
MY FIRST ASYNC I/O! (Exercise 4 of 13)
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'); | |
var content = fs.readFile(process.argv[2],function(err,data){ | |
if(err){ | |
console.log('error'); | |
} | |
var lines=data.toString().split('\n'); | |
console.log(lines.length-1); | |
}); |
const fs = require("fs");
const file = process.argv[2];
fs.readFile(file, "utf8", function (err, contents) {
if (err) {
return console.error(err);
}
const lines = contents.split("\n").length - 1;
console.log(lines);
});
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@Dipanshu27 the code seems to be wrong in this part :
var strFile = bufFile.toString();
The
callback (err,data)
second parameterdata
acts as the buffer.The modified code is :
Cheers ! 👍