Remove file in node.js :: node.js remove file

0
1173

I think you want to use fs.unlink.

More info on fs can be found here.

fs.unlink('fileToBeRemoved', function(err) {
    if(err && err.code == 'ENOENT') {
        // file doens't exist
        console.info("File doesn't exist, won't remove it.");
    } else if (err) {
        // other errors, e.g. maybe we don't have enough permission
        console.error("Error occurred while trying to remove file");
    } else {
        console.info(`removed`);
    }
});

LEAVE A REPLY

Please enter your comment!
Please enter your name here