adspace


How to truncate the file in Node.JS?

Answer Posted / Vikrant Nain

To truncate a file in Node.js, you can use the `truncate()` method of the FS module. Here's an example:

const fs = require('fs');
fs.truncate('/path/to/yourfile', 0, (err) => {
if (err) throw err;
console.log('File truncated!');
});

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is node js losing popularity?

590


How we can read a file in node js?

571