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

116
Views
How to create an express update route with multiple parameters

I want to update an attribute within a JSON object using fetch PUT. I've created a put function taking in 2 URL parameters
app.put('/trustRoutes/:id/:item', (req, res){

I am able to update the data with a single parameter but since I only want to change one value inside that object, calling put will replace the whole object with my new body.
below is what I've tried.

app.put('/trustRoutes/:id/:item', (req, res) => {
    readFile(data => {
 
      const userId = req.params['id/item'];
      // have also tried const userId = req.params.id.item
      data[userId] = req.body;
  
//write data back to file 

I looked around at other examples but couldn't find any that were updating data instead of GET. If there is one I missed please let me know.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

PUT requests are great for completely overwriting a resource, and is idempotent. This answer does a good job explaining idempotency. For updating a resource partially, a PATCH request is a better choice.

app.patch('/trustRoutes/:id/:item', (req, res) => {
    readFile(data => {
        data[userId] = req.params[id];
        data[item] = req.params[item];
        // A get request for this resource would now show both of the updated values
        // Write file
about 4 years ago · Juan Pablo Isaza 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!