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

Generating thumbnails

We created upload and download routes, but they do nothing to the image other than storing it locally. Picking on our first thumbnail route, let's change our download route to be able to tell us the size we want for the image:

app.param("width", (req, res, next, width) => {    req.width = +width;    return next();});app.param("height", (req, res, next, height) => {    req.height = +height;    return next();});

We start by defining two parameters, width, and height. These are numbers, so we'll assume they can be casted to a number type and stored in the request object.

Since we want to be able to specify sizes, let's create different routes using the route parameters we just introduced. To keep our code DRY, let's create a function ...

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