JavaScript/Nodejs : ajax POST request not passing object to backend
<p>I'm attempting to post a JSON object to my server, but when I console log <code>req.body</code> it shows an empty object. Here's my code:</p>

<pre><code>var submitRecipe = () =&gt; {

    let recipe = {alias: null, description: null, instructions: null};
    recipe.alias = document.getElementById('alias').value;
    recipe.description = document.getElementById('description').value;
    recipe.instruction = document.getElementById('instructions').value;

    postRequest("/createrecipe", recipe, (xhr) =&gt; {
        console.log("Hello!" + JSON.parse(xhr.responseText));
    })
};
var postRequest = (url, data, callback = undefined) =&gt; {

    xhr.onreadystatechange = () =&gt; {
        //Call a function when the state changes.
        if(xhr.readyState == 4 &amp;&amp; xhr.status == 200) {
            console.log("testing"); 
            return callback(200 , xhr.responseText);
        }else{
            return callback(400, xhr.responseText);
        }
    }
    xhr.open('POST', url)
    xhr.send(data);
}
</code></pre>

<p><strong>Node</strong></p>

<pre><code>createRecipe = function(req, res){

    console.log(req.body);
}
</code></pre>

<p>I'm using express to transfer the server information, and I am using <code>bodyParser.json()</code>. From there, I just call the controller with the following:</p>

<p><strong>express</strong></p>

<pre><code>var express = require("express");
var bodyParser = require("body-parser");

var server = express();

var recipeController = require("./controllers/recipeController");

server.use(bodyParser.json());
server.use(bodyParser.urlencoded({ extended: true}));


server.post("/createrecipe", recipeController.createRecipe);
</code></pre>

<p>The <code>createRecipe</code> function just console logs the information, but as stated before, <code>req.body</code> is an empty object. All tips are appreciated.</p>