const fs = require('fs'); const path = require('path'); const jimp = require('jimp') module.exports = function (image){ return new Promise ((resolve, reject)=>{ let imageAddress = path.join(__dirname + "/../public/images/" + image) let imageNameWithOutExtn = image.slice(0 , image.indexOf('.') ) jimp.read(imageAddress) .then(lenna => { return lenna .resize(157, 142) // resize .quality(90) // set JPEG quality .write(`./public/images/resized/${imageNameWithOutExtn}.png`); // save }) .then((res)=>{ try { fs.unlinkSync(__dirname + '/../public/images/' + image) console.log('original picture is deleted .....') console.log('----------------------------') } catch (err) { console.log(err); console.log('original picture not deleted .....') } resolve(res) }) .catch(err => { reject(err) }); }) }