how to delete image from the folder directly from a Request (MULTER)

imported item - 

const path = require('path')
const fs = require('fs')



// code :

router.get('/delete/:id',isAuth,async (req,res)=>{
    await  addBlogmodel.findByIdAndRemove(req.params.id,(err,items)=>{
        if(err){
            res.send("sory we have some issuse")
        }
        else
        {
            const path = './public/uploads/'+items.image
            try {
                fs.unlinkSync(path)
                res.redirect('/edit')
                //file removed
              } catch(err) {
                console.error(err)
              }
        }
    })
    
})

Comments

All time Best Post

Write a program that declares a class named Person. It should have instance variables to record name, age and salary. Use new operator to create a Person object. Set and display its instance variables.

IMAGE CRUD OPERATION USING EXPRESS MONGOOSE MULTER

connect websocket to binance api and store t he true value in the db

CRUD APP WITH SORT IN NODE EXPRESS AND MONGODB

express session login system using node express mongodb

calculate rsi

java program for 1 to 10 print using while loop

How to fetch last one minute volume of BTC in CCXT Nodejs.