How to Delete a File in Node.js

In NodeJS, to delete a file, you can use a quick and simple method in the “fs” module.

How to Delete a File in Node.js

//load the fs module
var fs = require('fs');

fs.unlink('/path/file.txt', function() {
  console.log("File deleted.");
});