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

235
Views
How do I call a function inside app.post in Node.js?

I am trying to create a node app in which I need to calculate the volume of the stl file which is uploaded by the user. I am using express and multer to handle the file uploading process. I am using three.js to calculate the volume of the stl file. However, when I add the volume code inside app.get(), it doesn't work. I have tried the code on plain js and it works perfectly and outputs the volume. I am not sure if the code gets executed when running on node as nothing gets printed in the terminal console. I need this code to work on the server side as I don't want the client to see this code and manipulate it. Please help me with this. Here is my current code:

app.get('/', function (req, res) {
    console.log("Hello!");                //This line gets printed
    res.render('pages/index');
});

app.post('/upload', upload.single('stl_file'), (req, res) => { //stl_file is the name attribute of input tag in html
    var loader = new STLLoader(); 
    loader.load(req.file, function (geometry) { 
        **Code to calculate volume**
        console.log("stl volume is " + volume);             //This line does not get printed
        **Code to calculate size**             
        let stlSize = size;
        console.log(stlSize);                              //This line does not get printed
    });
    return res.json({ status: 'OK'});
});

app.listen(3001);
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!