hi I'm using express file upload for uploading images in my NodeJS project but I need to resize the uploading image to 1000*1000 size and save to folder how can i do that
router.post('/add-product', (req, res) => {
// console.log(req.body)
let product=req.body
product.price=parseInt(product.price)
console.log(req.files.image);
let imgCount = req.body.len
producthelper.addProduct(req.body,(id)=>{
let image=req.files.image
if(imgCount == 1)
{
image.mv('./public/images/product-images/'+id+'-'+0+'.jpg',(err,done)=>{
if(err)
{
console.log(err)
}
})
}
else{
for(let i=0;i<imgCount;i++)
{
image[i].mv('./public/images/product-images/'+id+'-'+i+'.jpg',(err,done)=>{
if(err)
{
console.log(err)
}
})
}
}
req.flash('success_msg',"Successfully Added Your Product for Sell...")
res.redirect('/sellproduct')
})
})
this is my code to save the image in the folder how to replace the same?
You can use
sharp
npm package for that. For example.https://www.npmjs.com/package/sharp