Sunil M
Sunil M

Reputation: 1

Buffered output for fs.readfile() in Nodejs

why below code is giving buffered output even though "utf-8" is the default encoding?

    fs.readFile('includes/India2011.csv',function (err, data) {
    if (err) throw err;
    console.log(data);
    });

Upvotes: 0

Views: 783

Answers (1)

piscator
piscator

Reputation: 8699

From the documentation:

If no encoding is specified, then the raw buffer is returned.

You have to specify utf-8 encoding like this:

fs.readFile('includes/India2011.csv', 'utf-8', function (err, data) {
    if (err) throw err;
    console.log(data);
});

documentation

Upvotes: 2

Related Questions