-
-
Save adohe-zz/f6c2836cbd5357425dc6 to your computer and use it in GitHub Desktop.
A simple JavaScript to handle post request data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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