Wie man die Dateigröße in NodeJS / TypeScript mit Promises erhält

English Deutsch

Importieren Sie zuerst stat aus der NodeJS-Standardbibliothek:

import_stat.ts
import { stat } from "node:fs/promises";

Async-Await-Stil

filesize_async.ts
// Async-await style:
const statResult = await stat("myfile.pdf");
const fileSizeInBytes = statResult.size;

Promise.then()-Stil

filesize_then.ts
stat("myfile.pdf").then(statResult => {
    const fileSizeInBytes = statResult.size;
    // TODO your code goes here
});

Check out similar posts by category: NodeJS, Typescript