How to truncate the file in Node.JS?



How to truncate the file in Node.JS?..

Answer / 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

More Node.js Interview Questions

How to decode buffers?

1 Answers  


For node.js, why google uses v8 engine?

1 Answers  


Is a promise a callback?

1 Answers  


What is test pyramid? Explain with an example?

1 Answers  


How can we handle blocking I/O operations in Node.js?

1 Answers  


What is Node.js foundation?

1 Answers  


What functions are provided by path module in Node.js?

1 Answers  


What are lts releases? Why are they important?

1 Answers  


Is Nodejs client side or server side language?

1 Answers  


How to get post data in node.js?

1 Answers  


How to debug the code in Node.js?

1 Answers  


Are promises better than callbacks?

1 Answers  


Categories