File system
fs/promises.stat()
Retrieves metadata for a path, following symbolic links. Tested on Node.js 22.16.0. Metadata can change after the call. Use lstat to inspect a symlink itself, and do not rely on stat as an authorization check.
Formal Syntax & Structure
nodejs syntaxnodejs
fsPromises.stat(path[, options])Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| path | string | Buffer | URL | Path to a lab-owned file or directory. |
| options | object | Optional bigint mode. |
Return Value
Promise<Stats>
File metadata, with numeric representation depending on options.
Working Example
Example Snippetnodejs
import * as fs from 'node:fs/promises';import { join } from 'node:path';import { tmpdir } from 'node:os';const dir=await fs.mkdtemp(join(tmpdir(),'bytemind-ref-'));try { const file=join(dir,'book.txt');await fs.writeFile(file,'abc'); const s=await fs.stat(file);console.log(s.isFile(),s.size);} finally { await fs.rm(dir,{recursive:true,force:true}); }