How to get filesize in NodeJS / TypeScript using Promisese
First, import stat
from the NodeJS standard library:
import { stat } from "node:fs/promises";
Async-await style
// Async-await style:
const statResult = await stat("myfile.pdf");
const fileSizeInBytes = statResult.size;
Promise.then() style
stat("myfile.pdf").then(statResult => {
const fileSizeInBytes = statResult.size;
// TODO your code goes here
});