Thursday 18 October 2018

node.js: fs.unlink(path, callback): Remove a file or symbolic link asynchronously

fs.unlink(path, callback)
Remove a file or symbolic link asynchronously. Callback function takes an ‘err’ argument and it is called on unlink method execution.

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

var fileToRemove = 'input.txt';

fs.unlink(fileToRemove, (error) => {
    if (error) {
        console.log(`Unable to delete the file ${fileToRemove}, ${error}`);
    } else {
        console.log(`File ${fileToRemove} is removed successfully`);
    }
});



Previous                                                 Next                                                 Home

No comments:

Post a Comment