This library provides utility functions to check if a path is a file, directory, or symlink. It provides sync and async versions. e.g.:
import { isFile } from "path-type";
console.log(await isFile("package.json"));
//=> true
Node.js can do this natively via lstat:
import fs from "node:fs";
const stats = fs.lstatSync(filePath);
if (stats.isFile()) {
// path is a file
}
if (stats.isDirectory()) {
// path is a directory
}
if (stats.isSymbolicLink()) {
// path is a symlink
}
or asynchronously:
import fs from "node:fs";
const stats = fs.lstatSync(filePath);
if (stats.isFile()) {
// path is a file
}
if (stats.isDirectory()) {
// path is a directory
}
if (stats.isSymbolicLink()) {
// path is a symlink
}