I am reading a book on Node.js and it mentions the following code -
fs.stat(file, function(err, stats) {
console.log("File stats: " + stats);
});
It says this will produce output that looks something like this -
File stats:
{ dev: 234881026,
ino: 95028917,
mode: 33188,
nlink: 1,
uid: 0,
gid: 0,
rdev: 0,
size: 5086,
blksize: 4096,
blocks: 0,
atime: Fri, 18 Nov 2011 22:44:47 GMT,
mtime: Thu, 08 Sep 2011 23:50:04 GMT,
ctime: Thu, 08 Sep 2011 23:50:04 GMT }
However when I run this code I get the following output -
File stats: [object Object]
So is there a way of making the console.log() function more verbose so that it will print out the fields of objects?
Use:
console.log('File stats: ' + JSON.stringify(stats));
or
console.log('File stats:', stats);
concatenating strings result in conversion of stats to string and it becomes [object Object]. Try this:
fs.stat(file, function(err, stats) {
console.log(stats);
});