logo hsb.horse
← Back to snippets index

Snippets

Node.js File Check

Promise-based function to check if a path is a file in Node.js. Returns false on error.

Published: Updated:

Translations

Check if a path is a file in Node.js using Promises. Returns false on error, also serving as an existence check.

import fs from "node:fs/promises";
function isFile(path: string): Promise<boolean> {
return fs
.stat(path)
.then((stats) => stats.isFile())
.catch(() => false);
}