title: NodeJS get posted data - No framework
body: <p>Assuming I would like to get posted data into a variable in <code>/completed</code> case.
  How do I have to do ?
  I am able to retrieve data into request.on("data" ...) but if I log <code>data</code> into my <code>/completed</code>case, <code>data</code> is empty.</p>
  
  <pre><code>var http = require('http');
  http.createServer( function(request, response) {
      var data = "";
      if(request.method == 'POST') {
          request.on('data', function(chunk) {
              console.log('Received data:', chunk.toString());
              data += chunk.toString();
          });
          request.on('end', function() {
              console.log('Complete data:', data);
          });
      }
      switch (request.url) {
          case "/":
              response.writeHead(200, {'Content-Type': 'text/html'});
              response.write("&lt;a href='/form'&gt;Go to form&lt;/a&gt;");
              response.end();
              break;
          case "/form" :
              response.writeHead(200, {'Content-Type': 'text/html'});
              response.write("&lt;form method='POST' action='/completed'&gt;");
              response.write("&lt;input type='text' name='data1'/&gt;&lt;hr/&gt;");
              response.write("&lt;input type='text' name='data2'/&gt;&lt;hr/&gt;");
              response.write("&lt;input type='text' name='data3'/&gt;&lt;hr/&gt;");
              response.write("&lt;input type='file' name='data4'/&gt;&lt;hr/&gt;");
              response.write("&lt;input type='submit' value='Send'/&gt;");
              response.end("&lt;/form&gt;");
              break;
          case "/completed":
              console.log(request);
              response.writeHead(200, {'Content-Type': 'text/html'});
  
              // var post = ?
  
              response.end();
              break;
          default:
              response.writeHead(403, {'Content-Type': 'text/html'});
              response.end("Forbidden");
              break;
      }
  
  }).listen(1337);
  </code></pre>
  
  <p><em>Result</em></p>
  
  <pre><code>Received data: data1=dfs&amp;data2=ds&amp;data3=dvbcfgxrtgdw
  Complete data: data1=dfs&amp;data2=ds&amp;data3=dvbcfgxrtgdw
  </code></pre>