Reputation: 2580
In a nodejs server suppose I read a file like so:
fs.readFile('path/to/file','encoding',function(err,data){
//send data
res.end(data);
});
What type of object is data
, i.e is it a string, an array or something else?
Upvotes: 0
Views: 872
Reputation: 7437
From the docs:
The callback is passed two arguments (err, data), where data is the contents of the file.
If no encoding is specified, then the raw buffer is returned.
The raw buffer is a byte array. You can convert it to a javascript string by calling data.toString()
. For more conversion options, see the docs.
Upvotes: 1
Reputation: 4664
Without any options set,
http://nodejs.org/api/fs.html#fs_fs_readfile_filename_options_callback
If no encoding is specified, then the raw buffer is returned.
Upvotes: 1