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

217
Views
Node.js using multer, res.file returns undefined
const app = require('express')();
const PORT = 8080;
const multer = require('multer')
bodyParser = require('body-parser')
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())

app.listen(
    PORT,
    () => console.log(`it's alive on http://localhost:${PORT}`)
)

app.post('/user/self/pic', (multer({
    dest: '../uploads'
  }).single('image'), (req,res) => {
   
     console.log(req.file)
  
  }))

I'm building this most basic app using node.js. There's no front end implementation as our instructor doesn't allow any. Normally req.file will return basic info of the post request, but I tried many times and I'm getting undefined.

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

0

It seems there is a miss using in parentheses, try it:

app.post('/user/self/pic', multer({ dest: '../uploads' }).single('image'), (req, res) => {
  console.log(req.file);
});

And it is a better version:

const uploader = multer({ dest: '../uploads' }).single('image');
app.post('/user/self/pic', uploader, (req, res) => {
  console.log(req.file);
});
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!