How to get file size using nodejs

 Posted On  | Yashwant Chavan 

In this tutorial, You will learn how to get file size using 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:\\eclipse-jee-mars-1-win32-x86_64.zip");
console.log('File Size in Bytes:- ' + stats.size);

output

File Size in Bytes:- 288024166


© technicalkeeda.com 2017

 |  Find us on Google+ |  Rss Feed

Loaded in 0.0340 seconds.