Following is my nodejs code
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
app.use(bodyParser.json());
app.post('/', function(request, response) {
    console.log(request.body);
    console.log('post hit');
    response.json({
        message: 'Post Hit'
    });
});
app.listen(process.env.PORT || 8000);
following is my javascript code to call the above post end point
 $.ajax({
                    type: "POST",
                    crossDomain: "true",
                    url: "http://localhost:8000/",
                    data: {
                        "a": "b"
                    },
                    headers: {
                        "Content-Type": "application/json"
                    },
                    success: function(d) {
                        alert(d);
                        console.log(d);
                    },
                    error: function(e) {
                        console.log(e);
                        alert(e);
                    }
                });
I always get my request.body empty in node js.
Sometimes, the rest endpoint is not even hit.
I dont know how this works.
 
     
     
    