Node.js / Delete content in file

You are looking for fs.truncate or fs.writeFile

Either of the following will work:

const fs = require('fs')
fs.truncate('/path/to/file', 0, function(){console.log('done')})

or

const fs = require('fs')
fs.writeFile('/path/to/file', '', function(){console.log('done')})

There are also synchronous versions of both functions that can be useful in some scenarios.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)