Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

180
Views
I always get a problem if the image is already created

This project changes the image sizes this project is using a library called sharp, but at first, if the image is created for the first time, it does not cause problems, but it always shows me that problem if it was already created. In imageProcessing.ts File

import { Request, Response } from "express";
import fs, { promises as fsPromises } from 'fs';
import resizingTheImage from "./resizingTheImage";

const imageProcessing = async(req: Request, res: Response, next: Function): Promise<void | string> => {
    const widthValue = <string>req.query.width;
    const heightValue = <string>req.query.height;
    const nameFileValue = <string>req.query.namefile;

    const outputDir = `../../images/imageOutput/${nameFileValue}${widthValue}_${heightValue}.jpg`;

    const makeDir = async (): Promise<void> => {
        await fsPromises.mkdir('./images/imageOutput');
    };

    const imageProcessing = async (): Promise<void> => {
        try {
            await resizingTheImage(widthValue, heightValue, nameFileValue);
        } catch {
            res.send('There is a problem with the image processing');
        }
    };

    if (fs.existsSync(outputDir)) {
        return outputDir;
    } else {
        makeDir();
        await imageProcessing();
    }

    next();
}

export default imageProcessing;

In resizingTheImage.ts File

import sharp from "sharp";

const resizingTheImage = async (imageWidth: string, imageHeight: string, fileName: string): Promise<void> => {
    const imageDir: string = `./images/${fileName}.jpg`;
    const outputDir: string = `./images/imageOutput/${fileName}${imageWidth}_${imageHeight}.jpg`;

    if (isNaN(parseInt(imageWidth) && parseInt(imageHeight)) && fileName) {
        console.log("the inputs is Invalid")
    } else {
        await sharp(imageDir)
            .resize(parseInt(imageWidth), parseInt(imageHeight))
            .toFile(outputDir);
    }
}

export default resizingTheImage;

In error

[Error: EEXIST: file already exists, mkdir 'E:\Image Processing API\images\imageOutput'] {
  errno: -4075,
  code: 'EEXIST',
  syscall: 'mkdir',
  path: 'E:\\Image Processing API\\images\\imageOutput'
}
over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!