Answers for "get file size from fs.stat"

0

get file size from fs.stat

// In Megabytes

var fs = require("fs"); // Load the filesystem module
var stats = fs.statSync("myfile.txt")
var fileSizeInBytes = stats.size;
// Convert the file size to megabytes (optional)
var fileSizeInMegabytes = fileSizeInBytes / (1024*1024);
Posted by: Guest on June-21-2021
0

get file size from fs.stat

// In bytes

function getFilesizeInBytes(filename) {
    var stats = fs.statSync(filename);
    var fileSizeInBytes = stats.size;
    return fileSizeInBytes;
}
Posted by: Guest on June-21-2021

Browse Popular Code Answers by Language