How to get filesize in NodeJS / TypeScript using Promisese
First, import stat
from the NodeJS standard library:
example.ts
import { stat } from "node:fs/promises";
Async-await style
example.ts
// Async-await style:
const statResult = await stat("myfile.pdf");
const fileSizeInBytes = statResult.size;
Promise.then() style
example.ts
stat("myfile.pdf").then(statResult => {
const fileSizeInBytes = statResult.size;
// TODO your code goes here
});
Check out similar posts by category:
NodeJS, Typescript
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow