Home >Web Front-end >JS Tutorial >Instructions for using the fs.stat method in node.js_node.js

Instructions for using the fs.stat method in node.js_node.js

WBOY
WBOYOriginal
2016-05-16 16:26:371874browse

Method description:

Get file information.

Grammar:

Copy code The code is as follows:

fs.stat(path, [callback(err, stats)])

Since this method belongs to the fs module, the fs module needs to be introduced before use (var fs= require(“fs”) )

Receive parameters:

path file path

callback callback, passing two parameters, the exception parameter err, and the file information array stats

stats contains the following information: (The following information is the file information read in the case, not the default value)

Copy code The code is as follows:

{

dev : 0 ,

mode: 33206,

nlink : 1 ,

uid : 0 ,

gid : 0 ,

rdev : 0 ,

ino : 0 ,

size: 378 (bytes) ,

atime : Tue Jun 10 2014 13:57:13 GMT 0800 ,

mtime : Tue Jun 13 2014 09:48:31 GMT 0800 ,

ctime : Tue Jun 10 2014 13:57:13 GMT 0800

}

Example:

Copy code The code is as follows:

var fs = require('fs');
fs.stat('content.txt', function(err, stats){
if(err){
throw err;
}else{
console.log(stats);
}
})

Source code:

Copy code The code is as follows:

fs.stat = function(path, callback) {
callback = makeCallback(callback);
if (!nullCheck(path, callback)) return;
binding.stat(pathModule._makeLong(path), callback);
};
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn