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

305
Views
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 answers
Answer question

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 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!