Answer the question
In order to leave comments, you need to log in
How to check if a file is empty?
Greetings, there is such an interesting module for node.js called fs .
The task is this: I need to check the existence of the contents of the file and, under certain conditions, do something with this file.
Well, i.e. IF the file is empty, then delete it, for example.
Either I'm not careful, or there are problems with the perception of some methods of this module. Tell me, please, how to perform such a check? If there are analogues of more interesting analogues, then advise.
Thank you.
Answer the question
In order to leave comments, you need to log in
const stat = fs.statSync('./path/to/file');
console.log(stat.size);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question