Overview
This node retrieves detailed information about a specified file or directory on the filesystem. It is useful for workflows that need to inspect files or directories, gather metadata, or perform conditional logic based on file attributes. For example, it can be used to verify file existence and properties before processing, audit directory contents, or extract file samples for preview.
Common scenarios include:
- Checking if a file exists and obtaining its size, type, and timestamps.
- Gathering directory statistics such as counts of files and subdirectories.
- Extracting a small content sample from a file for quick inspection.
- Calculating an MD5 checksum to verify file integrity.
- Resolving symbolic links to their real paths.
Properties
| Name | Meaning |
|---|---|
| Path | The path to the file or directory to get information about (e.g., /path/to/file/or/directory). |
| Include Options | Collection of optional features to include additional data: |
| - MIME Type Detection | Whether to detect and include the MIME type for files (e.g., text/plain, image/jpeg). |
| - File Content Sample | Whether to include a small sample of the file content (first 200 characters). |
| - Directory Contents Count | Whether to count the number of files, subdirectories, and other items inside a directory. |
| - Checksum (MD5) | Whether to calculate the MD5 checksum for files. |
| - Real Path Resolution | Whether to resolve symbolic links to their actual real paths. |
Output
The output is an array of JSON objects, each representing detailed information about one input file or directory. Each object contains:
path: Absolute resolved path.name: Base name of the file or directory.directory: Parent directory path.extension: File extension (empty for directories).type: One of"file","directory", or"other".size: Size in bytes.sizeHuman: Human-readable size string (e.g., "1.23 MB").created,modified,accessed: Timestamps for creation, modification, and last access.isFile,isDirectory,isSymbolicLink: Boolean flags.permissions: Object with mode, octal representation, and booleans for readable, writable, executable.owner: Object with user ID (uid) and group ID (gid).blocks,blockSize,device,inode,hardLinks: Filesystem metadata.- Optional fields depending on options selected:
realPath: Resolved real path if symbolic link resolution enabled.mimeType: Detected MIME type if enabled and item is a file.contentSample: String containing first 200 characters of file content.contentSampleSize: Number of characters included in the sample.isBinary: Boolean indicating if the sampled content is binary.contents: Object with counts of files, directories, others, and total items inside a directory.checksum: MD5 checksum string for files.
- Error fields like
realPathError,contentSampleError,contentsError, orchecksumErrormay appear if respective operations fail.
If an error occurs and the node is set to continue on failure, the output will contain an object with an error message and the original path.
Dependencies
- Node.js built-in modules:
fs(filesystem),path. - Utility functions for formatting file sizes, detecting MIME types, checking binary content, and calculating MD5 checksums are bundled internally.
- No external API keys or services are required.
- Requires appropriate filesystem permissions to read file stats, contents, and directories.
Troubleshooting
- Common issues:
- Invalid or non-existent file/directory path will cause an error.
- Insufficient permissions to read the file or directory.
- Symbolic link resolution may fail if the link is broken.
- Reading large files for content sample or checksum may be slow or resource-intensive.
- Error messages:
"File path is required": The path property was empty or missing."Path not found: <resolved_path>": The specified path does not exist.- Errors related to reading files or directories will be reported in the output under specific error fields.
- To resolve errors, ensure the path is correct, accessible, and the node has necessary permissions.
Links and References
- Node.js fs module documentation
- Node.js path module documentation
- MDN Web Docs: File System Access (for general understanding)