Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does it mean that "file is truncated" for the 'w' file system flag?

Tags:

node.js

In the documentation for the Node.js fs module, under "File System flags", it says:

'w' - Open file for writing. The file is created (if it does not exist) or truncated (if it exists).

Truncated to what size? 0 bytes?

like image 647
Chad Avatar asked Sep 06 '25 03:09

Chad


1 Answers

Yes, the 'w' flag will truncate the file to 0 bytes before writing -- effectively overwriting the file if it exists. (As opposed to the 'a' flag, which will append to the end of an existing file.)

like image 120
Chad Avatar answered Sep 07 '25 22:09

Chad