Friday 5 May 2017

nodejs: Unable to read file contents

I am trying to read the contents of a file. The file existence check passes, even then the file read excepts as shown below:

var fs = require('fs')
fs.exists('c:\\abc.txt',function(exists){
    console.log("exists");
    fs.readFile('c:\\abc.txt', 'UTF-8', function (err,data) {
            if (err) {
                console.log("err"+err);
            }            
            console.log("data:"+data);                
    });
});

Output

exists
errError: ENOENT: no such file or directory, open 'c:\abc.txt'
data:undefined

How may I correct this.



via StillNestling

No comments:

Post a Comment