title: How to delete data, using Rest api in an array stored in a JSON file, based on http request that's made by user?
body: <p>I have a task that requires me to delete some data in an array that is in a JSON file, using node/express. I want, when a delete request is made, to delete a specific item that matches a specific id in the array that is in the JSON file. I tried using the filter method, but it doesn't seem to work.</p>
  <p>JS file:</p>
  <pre><code>var obj = { projects: []};
  app.post('/', (req, res, next)=&gt;{
      let identifier = req.query.identify; //id of project
  
      fs.readFile('webProjects.json', (err, data)=&gt;{
          if(err) throw err;
              obj = JSON.parse(data);
              obj.projects.push({id:identifier, game: req.query.project});
              let json = JSON.stringify(obj);
              fs.writeFile('webProjects.json', json, (err)=&gt;{
                  if(err) throw err
                  console.log(&quot;updatedd&quot;)
              })
      })
  })
  
  /*when user sends delete request, delete specific data.*/
  app.delete(&quot;/&quot;, (req, res, next)=&gt;{
  
      fs.readFile('webProjects.json', (err, data)=&gt;{
          console.log(data)
          obj = JSON.parse(data);
          obj.projects.filter((item)=&gt;{
              let url = req.query.identify; 
              return item.id !== url;
          })
          console.log(obj)
          let json = JSON.stringify(obj);
          fs.writeFile('webProjects.json', json, (err)=&gt;{
              if(err) throw err;
              console.log(obj)
          })
      })
  })
  
  /*when user navigates to another page, we display the data of the resource*/
  app.get('/:id', (req, res, next)=&gt;{
      fs.readFile('webProjects.json', (err, data)=&gt;{
       if (err) throw err
       res.send(data);
      })
  })
  
  
  /*we want to catch all errors, with the requests made to the server.
  used the wildcard(*) to make sure that we catch all requests made to the server.
  */
  app.get('*', (req, res, next)=&gt;{
      let err = new Error('There was an error in accessing the page you wanted');
      err.statusCode = 404;
      next(err);
  })
  
  app.use((err, req, res, next)=&gt;{
      console.log(err.message)
      if(!err.statusCode) err.statusCode = 500;
      res.status(err.statusCode).send(err.message);
  })
  
  app.listen(8080, ()=&gt;{
      console.log(&quot;server has listened&quot;)
  })
  </code></pre>
  <p>JSON file/data:</p>
  <pre><code>{&quot;projects&quot;:[{&quot;id&quot;:&quot;1&quot;,&quot;game&quot;:&quot;miniGame&quot;},{&quot;id&quot;:&quot;2&quot;,&quot;game&quot;:&quot;min&quot;}]}
  </code></pre>