Here is my server code. I want to show the resized images from the output folder, And here resize is a custom js created by me just to take image parameters and resize it. After resizing I want to show the image from the output folder.
const express = require('express');
const files = require('fs');
const resize = require('./resize.js');
const server = express();
const port = 200;
server.get('/', function (req, res) {
const PicName = req.query.name;
const widthString = req.query.width;
const heightString = req.query.height;
const PicFormat = req.query.format;
let width;
let height;
if (widthString) {
width = parseInt(widthString);
if (width < 1) {
res.send('<h1>Error in parameter</h1>');
return;
}
}
if (heightString) {
height = parseInt(heightString);
if (height < 1) {
res.send('<h1>Error in parameter</h1>');
return;
}
}
if (PicFormat === 'gif') {
res.send('<h1>Error in format</h1>');
return;
}
files.access(`./images/${PicName}`, files.constants.F_OK, function (err) {
if (err) {
res.send('<h1>Image does not Exist</h1>');
return;
}
res.type(`image/${PicFormat || 'jpg'}`);
resize(`./images/${PicName}`, PicFormat, width, height).toFile(
`./output/${PicName}`
);
resize(`./images/${PicName}`, PicFormat, width, height).pipe(res);
});
});
server.listen(port, function () {
console.log(`Example app listening at http://localhost:${port}`);
});

./images/${PicName}, PicFormat, width, height).toFile(./output/${PicName}); resize(./images/${PicName}, PicFormat, width, height).pipe(res); }); I have to do the resizing repeatedly to show the image. I want to do is resize once and show the image from the resized image folder to the localhost