node.js parse JSON of request

Viewed 53134

I am sending a credentials JSON object with the following request to node.js:

credentials = new Object();
credentials.username = username;
credentials.password = password;

$.ajax({
    type: 'POST',
    url: 'door.validate',
    data: credentials,
    dataType: 'json',
    complete: function(validationResponse) {
        ...
    }
});

On the server side i would like to load the submitted credentials into a JSON object to use it further on..

However, I don't know how to get the JSON out of the req object...

http.createServer(
    function (req, res) {
         // How do i acess the JSON
         // credentials object here?
    }
).listen(80);

(i have a dispatcher in my function(req, res) passing the req further on to controllers, so i would not like to use the .on('data', ...) function)

2 Answers
Related