Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

307
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda