How to Get File Size in Node JS?
We are from free coder. We are a group of web developers who are passionate about web development. You can learn from us php, laravel, node js, vue js, react js and many other topic on web developement.
we are very happy to help you.
Today what you are going to learn:
This article will give you lesson of how to get file size in node js. you will learn node js get file size. We will look at lesson of node js get file size in mb. i would like to share with you how to check file size in node js.
We will use fs npm package for find file size using node.js. fs package provide statSync() for getting file size in mb. let's see simple lesson
Lesson 1: Create Node App
run bellow command and create node app.
Lesson 2: Create server.js file
Make sure, you have add file on "uploads/best-open-source.jpg" path.
const fs = require('fs');
const filePath = './uploads/best-open-source.jpg';
var fileInfo = fs.statSync(filePath);
var fileSize = fileInfo.size;
var fileSizeMB = fileInfo.size / (1024*1024);
console.log('File Size:' + fileSizeMB);
console.log('File Size in MB:' + fileSizeMB);
now you can simply run by following command:
thank you very much for following up with me.
- React JS
- Typeahead JS
- Facebook API
- Amazon API
- Twitter API
- Instagram API
- Google API
- Node JS
- Mailchimp API
- Linkedin API
- Dropbox API
- Mailgun API
- Chart JS
- Parsley JS
- Rakuten Marketing API
- Behance API
- Google Map
- Mediafire API
- Ionic Framework
- React Native