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 |
How to decode buffers?
For node.js, why google uses v8 engine?
Is a promise a callback?
What is test pyramid? Explain with an example?
How can we handle blocking I/O operations in Node.js?
What is Node.js foundation?
What functions are provided by path module in Node.js?
What are lts releases? Why are they important?
Is Nodejs client side or server side language?
How to get post data in node.js?
How to debug the code in Node.js?
Are promises better than callbacks?