...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
var http = require('http'); var qs = require('querystring'); http.createServer(function (request, response) { console.log(request.method); console.log(request.url); if (request.method == 'POST') { var body = ''; request.on('data', function (data) { body += data; // Too much POST data, kill the connection! // 1e6 === 1 * Math.pow(10, 6) === 1 * 1000000 ~~~ 1MB if (body.length > 1e6){ request.connection.destroy(); } }); request.on('end', function () { var postData = qs.parse(body); console.log(postData); // use post['blah'], etc. }); } response.writeHead(200, {'Content-Type': 'text/plain'}); response.end('Hello World\nThis can be viewed in browser'); }).listen(3333, '127.0.0.1'); console.log('Server running at http://127.0.0.1:3333/'); |
...