Get full details on a file or directory.
var stat = require( '@stdlib/fs/stat' );Asynchronously returns file system statistics for a file or directory.
The callback is invoked with an fs.Stats object containing methods and values describing the target path.
stat( 'package.json', onStat );
function onStat( error, stats ) {
if ( error ) {
throw error;
}
console.log( stats );
}Asynchronously returns file system statistics for a file or directory with options.
stat( 'package.json', {
'bigint': true
}, onStat );
function onStat( error, stats ) {
if ( error ) {
throw error;
}
console.log( stats );
}Options:
- bigint:
booleanflag indicating whether numeric values should be returned asbigint. Default:false.
stat( 'package.json', onStat );
function onStat( error, stats ) {
if ( error ) {
throw error;
}
console.log( stats );
}Synchronously returns file system statistics for a file or directory.
var out = stat.sync( 'package.json' );
if ( out instanceof Error ) {
throw out;
}
console.log( out );Synchronously returns file system statistics for a file or directory with options.
var out = stat.sync( 'package.json', {
'bigint': true
});
if ( out instanceof Error ) {
throw out;
}
console.log( out );The returned fs.Stats instance provides these type-check methods:
isFile()isDirectory()isBlockDevice()isCharacterDevice()isFIFO()isSocket()isSymbolicLink()
The returned fs.Stats instance also provides values such as fs.Stats:
dev,ino,mode,nlink,uid,gid,rdev,size,blksize,blocksatime,mtime,ctime,birthtimeatimeMs,mtimeMs,ctimeMs,birthtimeMsatimeNs,mtimeNs,ctimeNs,birthtimeNs(available whenbigint: true)
var out = stat.sync( 'package.json' );
if ( out instanceof Error ) {
throw out;
}
console.log( out );var stat = require( '@stdlib/fs/stat' );
var out = stat.sync( 'package.json' );
if ( out instanceof Error ) {
throw out;
}
console.log( out.isFile() );
stat( 'package.json', onStat );
function onStat( error, stats ) {
if ( error ) {
throw error;
}
console.log( stats );
}Usage: stat [options] <path>
Options:
-h, --help Print this message.
-V, --version Print the package version.
- Relative paths are resolved relative to the current working directory.
- Errors are written to
stderr. - Results are written to
stdoutas JSON.