Skip to content
Advertisement

How to find the size of the file in Node.js?

I am using multer for uploading my images and documents but this time I want to restrict uploading if the size of the image is >2mb. How can I find the size of the file of the document? So far I tried as below but not working.

JavaScript

Can anyone please help me?

Advertisement

Answer

To get a file’s size in megabytes:

JavaScript

or in bytes:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement