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

153
Views
How to return body in REQUEST nodejs

I just want to return a body but I get only {} instead real data.

const Ocr = (file,req,response) => {

    const options = {
        method: "POST",
        url: "https://api.aiforthai.in.th/ocr",
        headers: {
            "Apikey": "LgArg8PNY2BiY1cmtFsE1XXN6bP6O903",
            "Content-Type": "multipart/form-data"
        },
        formData: {
            "uploadfile": fs.createReadStream(file)
        }
    };

    request(options, function (err, res, body) {
        if (err) {
            console.log(err)
            return 
        }
        return body //here I want to return
    });

};

And this is my main function that call the top code.

exports.testOcr = async (req, res, next) => {
    try {
        const file = "docs/uploadsNotice/65/กรุงเทพ.jpg"
        const result = await requestOcr.Ocr(file)
        return res.status(200).json({
            data: result,
        });
    } catch (error) {
        next(error);
    }
};

My function is not returning body

Can someone please help me with this?

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

0

Are you sure you are using json body-parser as a middle-ware, if not, there won't be a body on req.body.

you can install body-parser via npm: npm install body-parser

and then use the middle-ware as shown below:


    const bodyParser = require("body-parser");
    app.use(bodyParser.json())

for more information check the official express docs here.

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!