How To Get File Size Using Node.js

By Yashwant Chavan, Views 14815, Last updated on 03-Mar-2019

In this tutorial, You will learn how to get file size using nodejs.

tags nodejs

Node.js file size example

require('fs') - Load the File System module

fs.statSync(path) method returns the instance of fs.Stats

fs.Stats contains below properties, out of that, you can use size property to get the file size.

  dev: 2114,
  ino: 48064969,
  mode: 33188,
  nlink: 1,
  uid: 85,
  gid: 100,
  rdev: 0,
  size: 527,
  blksize: 4096,
  blocks: 8,
  atime: Mon, 10 Oct 2011 23:24:11 GMT,
  mtime: Mon, 10 Oct 2011 23:24:11 GMT,
  ctime: Mon, 10 Oct 2011 23:24:11 GMT,
  birthtime: Mon, 10 Oct 2011 23:24:11 GMT
var fs = require('fs');
var stats = fs.statSync("c:\\");
console.log('File Size in Bytes:- ' + stats.size);


File Size in Bytes:- 288024166


Hi there! I am founder of and programming enthusiast. My skills includes Java,J2EE, Spring Framework, Nodejs, PHP and lot more. If you have any idea that you would want me to develop? Lets connect: yashwantchavan[at][]