Skip to content

Get file size in Node.js

To get file size in Node.js, the following code snippet would help. statSync() method from fs package synchronously returns information about the given file path the file size in bytes.

var fs = require('fs');
var stats = fs.statSync("/home/anand/Documents/bg.png");
console.log('File Size in Bytes:- ' + stats.size);
Advertisements
//Sample Output
{
  dev: 2114,
  ino: 48064969,
  mode: 33188,
  nlink: 1,
  uid: 85,
  gid: 100,
  rdev: 0,
  size: 231527,
  blksize: 4096,
  blocks: 8,
  atime: Mon, 10 Oct 2021 14:54:12 GMT,
  mtime: Mon, 10 Oct 2021 14:54:12 GMT,
  ctime: Mon, 10 Oct 2021 14:54:12 GMT,
  birthtime: Mon, 10 Oct 2021 14:54:12 GMT
}s

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.