File size in NodeJS

This tutorial will explain the steps to determine the file size in bytes using NodeJS

NodeJS provides the inbuilt fs library which can be used for all file related methods. The file size can also be determined using this library

Create a reference variable for fs libray and use the statSync method on the required filePath

const fs = require("fs");
const path = require("path");
const filePath = path.normalize(path.join(__dirname, "../temp/", fileUrl))
const stats = fs.statSync(filePath);
const sizeInBytes = stats.size;

Leave a Reply