title: Sending a CSV file from browser to nodejs server
body: <p>I am trying to send a csv file which is uploaded by the user, from browser to nodejs server for processing (file is over 50 mb, so the page becomes unresponsive). I'm using XMLHttpRequest for this purpose. I cannot find a solution to this. Any help is appreciated.</p>
  
  <h3>Javascript code</h3>
  
  <pre><code> var csv = document.getElementById('inputFile').files[0];
   var request = new XMLHttpRequest();
   request.open("POST", "/handleFile", true);
   request.setRequestHeader("Content-type", "text/csv");
   request.onreadystatechange = function() {
     if (request.readyState === XMLHttpRequest.DONE &amp;&amp; request.status === 200) {
       console.log("yey");
     }
   }
  
   request.send(csv);
  </code></pre>
  
  <h3>NodeJS server</h3>
  
  <pre><code> var express = require('express')
   var app = express()
   var bodyparser = require('body-parser')
  
   app.post('/handleFile', function(req, res) {
     console.log(req.body); // getting {} empty object here....
     console.log(req);
  
     var csv = req.body;
     var lines = csv.split("\n");
     var result = [];
     var headers = lines[0].split("\t");
  
     for (var i = 1; i &lt; lines.length; i++) {
       var obj = {};
       var currentline = lines[i].split("\t");
  
       for (var j = 0; j &lt; headers.length; j++) {
         obj[headers[j]] = currentline[j];
       }
  
       result.push(obj);
     }
  
     fileData = result;
   });
  </code></pre>
  
  <p>What did I do wrong? Is the XMLHttpRequest used incorrectly? or there is some other thing that i did not understand ? why is there no data in req.body even though its a post request. 
  Or is there any other way to send a csv/text file to nodejs server from front end.</p>
  
  <p>This question is not a duplicate because, the body-parser i.e. the middleware responsible for parsing the req.body does not handle text/csv and multipart/form-data . The above link is not the correct solution.</p>