T
T
Tolik2014-05-09 21:41:05
Node.js
Tolik, 2014-05-09 21:41:05

What is the easiest way to get data from a POST request to node.js?

But without using any frameworks, etc., i.e. on pure node

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene Obrezkov, 2014-05-09
@Diel

http.createServer(function (req, res) {
if (req.method == 'POST') {
    req.on('data', function(chunk) {
      console.log("Received body data:");
      console.log(chunk.toString());
    });
   
    req.on('end', function() {
      // empty 200 OK response for now
      res.writeHead(200, "OK", {'Content-Type': 'text/html'});
      res.end();
    });    
  }
}).listen(1337);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question