For now I use
fs.openSync(filepath, 'a')
But it’s a little tricky. Is there a ‘standard’ way to create an empty file in Node.js?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you want to force the file to be empty then you want to use the
'w'flag instead:That will truncate the file if it exists and create it if it doesn’t.
Wrap it in an
fs.closeSynccall if you don’t need the file descriptor it returns.