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

317
Views
What is a UnhandledPromiseRejectionWarning: ReferenceError in Node Javascript?

I had working express Node Javascript code, but when I changed the code to give me a random id for each file input (instead of a set file name, myFile.jpeg), I get the following error:

UnhandledPromiseRejectionWarning: ReferenceError: fileName is not defined

I know that I've defined the fileName, but I don't understand what this error means or how to fix it. I've seen this error a lot of Discord bots or MongoDB, but I'm having a hard time finding anything for express.

let rid = Math.floor(Math.random() * 10000000)
let ridString = "" + rid
//const upload = multer().single('myfile')
const upload = multer().single(ridString)

//other code

app.post('/upload', (req, res)=>{
    upload(req, res, async function(err){ 
     if( err|| req.file === undefined){
         console.log(err)
         res.send("error occured")
     }else{
        //let rid = Math.floor(Math.random() * 10000000)
        //let ridString = "" + rid
        let fileName = ridString + ".jpeg"
        //let fileName = "myfile.jpeg"
        var image = await sharp(req.file.buffer)
        //.catch(err => {console.log('error: ', err)})
        .jpeg({
            //quality: 40,
        }).toFile('./uploads/'+fileName)
        .catch( err => { console.log('error: ', err) })
        pythonFunction(res, fileName);
     }
    })
})

I've commented out everything that got changed from myFile to the random number.

about 4 years ago · Juan Pablo Isaza
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!