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

303
Visualizações
I can't call PATCH method using Pug, Mongoose and Express.js

I am new to code and I apologize in advance for all my noob mistakes.

I'm trying to set a new color to an existing object stored in MongoDB using the PATCH method in the browser, but I don't understand why its not working while the GET and POST methods are working.

I have to mention that the PATCH method works in Postman.

The code in my pug file:

        form(action=`/posts/changeColor` + id, method="patch")
            label Enter variable color:
                    input(type="text", name="color")
            button(type="Submit") Submit

And the code in express:

    router.patch('/posts/changeColor/:id', async(req, res)=>{
        try{
            const test = await products.updateOne({_id: req.params.id},{$set:{productColor: req.body.color}});
            res.json(test);
        }catch(err){
            console.log(err);
        }
    }

This is the error I get after pressing the "Submit" button

    Cannot GET posts/changeColor/62723c3ed31baa41d5e9b0e1
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

HTML forms can not initiate PATCH HTTP requests.

See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form#attr-method

over 4 years ago · Santiago Trujillo Relatório
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