Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

238
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda