O'Reilly logo

Hands-On Microservices with Node.js by Diogo Resende

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Manipulating images

Let's add the other image manipulation options we mentioned before. Let's use the Sharp naming for flipping. We'll use the query parameter flip to flip the image vertically, and the query parameter flop to flip it horizontally. We'll also add the optional query parameters blur and sharpen, which should be positive numbers.

Our image download function can be reintegrated directly in our download route, since we only have one route now. In the end, we would end up with something like this:

app.get("/uploads/:image", (req, res) => {    fs.access(req.localpath, fs.constants.R_OK , (err) => {        if (err) return res.status(404).end();        let image     = sharp(req.localpath);        let width     = +req.query.width;        let height    = +req.query.height;

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required