Skip to content

Instantly share code, notes, and snippets.

@adohe-zz
Created July 17, 2014 06:06
Show Gist options
  • Select an option

  • Save adohe-zz/f6c2836cbd5357425dc6 to your computer and use it in GitHub Desktop.

Select an option

Save adohe-zz/f6c2836cbd5357425dc6 to your computer and use it in GitHub Desktop.
A simple JavaScript to handle post request data
var http = require('http'),
iconv = require('iconv-lite');
var server = http.createServer(function (req, res) {
var chunks = [],
size = 0,
finish = function (res) {
res.end('beepboop\n');
};
req.on('data', function (chunk) {
chunks.push(chunk);
size += chunk.length;
});
req.on('end', function () {
var buf = Buffer.concat(chunks, size);
var str = iconv.decode(buf, '<encoding>');
console.log(str);
finish(res);
});
});
server.listen('<port>');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment