title: How to pass name or ID of a button to Node using fetch
body: <p>I have a table that is filled with items from database and I'd like to have a button in every row that deletes that item from the database. My aproach was to give the button same id/name as the specific data it would be deleting but I don't know how to pass that id to node so it knows which exact item to delete. I am using fetch in js to make the POST with that button. </p>
  
  <p>I'm using node with express, and I use ejs as my templating solution. My database is mongodb with mongoose. </p>
  
  <p>This is the button, it is generated for every item in database and it has the same id as the item from database. </p>
  
  <pre><code>&lt;button class="delete-button" id='&lt;%= item._id %&gt;'&gt;X&lt;/button&gt;
  </code></pre>
  
  <p>This is the fetch. Whole thing is in forEach to add the listener to each of the buttons</p>
  
  <pre><code>button.addEventListener('click', () =&gt; {
      fetch('/delete', { method: 'POST' })
        .then(function (response) {
          if (response.ok) {
            console.log('Delete was recorded')
            return
          }
          throw new Error('Request failed.')
        })
        .catch(function (error) {
          console.log(error)
        })
    })
  </code></pre>
  
  <p>and this is app.post in node. </p>
  
  <pre><code>app.post('/delete', (req,res)=&gt;{
      console.log("Deleted button has been clicked")
  })
  </code></pre>
  
  <p>This works just fine, but I don't know how to pass the id to node.</p>
  
  <p>Thank you in advance</p>