Thursday, 18 October 2018

node.js: fs.unlinkSync(path): Remove a file or symbolic link asynchronously

fs.unlinkSync(path)
This method removes a file or symbolic link asynchronously.

HelloWorld.js
var fs = require('fs');

var fileToRemove = 'input.txt';

if(fs.existsSync(fileToRemove)){
 console.log(`Removing the file ${fileToRemove}`)
 fs.unlinkSync(fileToRemove);
}else{
 console.log(`File ${fileToRemove} not exists`);
}


Previous                                                 Next                                                 Home

No comments:

Post a Comment