Answers for "delete attachments in nodejs"

0

delete attachments in nodejs

// NOTE: `file_name` values are obfuscated and uniquely generated by the client.
// The actual file name is in data storage.
app.post('/delete/:file_name', (req, res) =>
{
    const theFile = 'attachments/' + req.params.file_name;

    var resultHandler = function(err) { 
        if(err) {
           console.log("file delete failed", err);
           return res.status(500).json(err)
        }
        console.log("file deleted");
        return res.status(200).send({data: req.params.file_name + ' deleted'});
    }
    
    fs.unlinkSync(theFile, resultHandler);
});
Posted by: Guest on December-03-2020

Code answers related to "TypeScript"

Browse Popular Code Answers by Language