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

224
Views
Cannot resolve nodejs files path on exported to another directory

I have a problem with display file path because not sure why but node is unable to display it.

If I am using req.file.filename it is working just fine but I need to process the loaded file so when I am exporting to a directory I need to use something like the second variable FILE_OUTPUT and in that case the path is not recognised anymore, any idee why is behaving like that?

The path is looking like: /Users/jimmy/work/task/running/public/output/xs_1634558545319.png and should be : output/xs_1634558545319.png

app.post("/exit", upload.single("pic"), function (req, res, next) {

  const FILE_INPUT = path.join(__dirname, req.file.path) ;

  const FILE_OUTPUT = path.join(__dirname, `/public/output/xs_${req.file.filename}`); ;
  
  im.convert([FILE_INPUT, '-resize', '100x100', FILE_OUTPUT], 
  function(err, stdout){
    if (err) throw err;

    console.log('stdout:', stdout, FILE_OUTPUT, FILE_INPUT);

  });
});
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

you need to use path.basename:

const FILE_OUTPUT = path.basename(`/public/output/xs_${req.file.filename}`);
about 4 years ago · Juan Pablo Isaza Report
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!