Access data send by xhr request in node.js Access data send by xhr request in node.js express express

Access data send by xhr request in node.js


Because of how bodyParser accepts the body of a request, you have to set the request header "Content-Type" to 'application/json' for your request to work properly. This is very simple to accomplish; a simplexmlhttp.setRequestHeader('Content-Type', 'application/json') will do the trick.


You can read the request body via req.body:

app.post('/', function(req,res){  console.log("request method :" + req.method);  console.log("request body :" + req.body);  res.end("OK");});