Search

var sys = require('sys'),
http = require('http'),
qs = require('querystring');
http.createServer(function(request, response) {
// data is a string that will be used to join all the chunks
// the POST will be an object with the data from the post
var data = '',
POST;
request.on('data', function(chunk) {
// each time a little chunk (a piece of string) is
// sent to the server the 'data' event is fired
console.log(chunk);
// here is the joining
data += chunk;
});
request.on('end', function(){
// when the 'end' event is fired, then you can
// convert the data to an object with the qs.parse
POST = qs.parse(data);
});
setTimeout(function() {
response.writeHead(200, {'Content-Type': 'application/json',
'Access-Control-Allow-Origin': "*"});
response.write(JSON.stringify(POST));
response.end();
}, 2000);
}).listen(8000);