title: Add parameters to post request using js on client side
body: <p>I'm developing a "TODO" app using node.js and mongodb.</p>
  
  <p>I'm trying to post a new task from the client but I didn't success to pass parameters to the server and from there to the database.</p>
  
  <p>Client code:</p>
  
  <pre><code> &lt;script&gt;
    function addData(item, url) {
      var text = document.getElementById("myTask").value;
       return fetch('/todos',{
        method: 'post',
        body: text
              }).then(response =&gt; response.json())
        .then(data =&gt; console.log(data));
    }
  &lt;/script&gt;
  </code></pre>
  
  <p>Server code:</p>
  
  <pre><code>    app.post('/todos',(req,res) =&gt;{
    console.log("\n\n req.body is:  \n\n",req.body);
    var todo = new Todo({
      text: req.body.text});
      todo.save().then((doc) =&gt;{
        res.send(doc);
        console.log(JSON.stringify(doc,undefined,2));
      },(err) =&gt;{
        res.status(400).send(err); //400 = unable to connect
        console.log("Unable to save todo.\n\n\n" , err);
      });
    });
  </code></pre>
  
  <p>And the problem is that the client doesn't send the body to the server, 
  and the body is null on the server side:
  <a href="https://i.stack.imgur.com/2EU2b.png" rel="nofollow noreferrer">See the logs here</a>
  (as you can see: req.body = {})
  In the js code, I tried to pass the body parameter but I guess I did something wrong so I want to know the best way to pass parameters back to the server (not only the body but text, time and etc)</p>
  
  <p>Thank in advance,
  Sagiv</p>