title: How to return data in a post request in express.js?
body: <p>Inside my react frontend, I have a handler called handleDrop, the code looks like:</p>
  
  <pre><code>         handleDrop(files) {
            var data = new FormData();
  
            alert((files[0]) instanceof File);
            files.forEach((file, index) =&gt; {
              data.append('file' + index, file);
            });
  
            fetch('/file_upload', {
              method: 'POST',
              body: data
            }
  </code></pre>
  
  <p>At my express backend, I have a post handler for this fetch request where I iterate over the uploaded data and figured out the most frequent word. The code looks like:</p>
  
  <pre><code>app.post('/file_upload', function(req , res){
      var dictCount ={};
      var storage = multer.diskStorage({
          destination: mypath
      });
      var upload = multer({
          storage: storage
      }).any();
  
      upload(req, res, async err =&gt; {
        try {
          if (err) {
            console.log(err);
            return res.end('Error');
          } else {
            await bluebird.each(req.files, async item =&gt; {
              const data = fs.readFileSync(item.path);
  
             // figure out the word count here
  
            var topFeatures = {};
  
            Object.keys(dictCount).forEach(function(key) {
              console.log(dictCount[key].count);
                if(dictCount[key].count&gt;6){
                    topFeatures[key] = {word:key, count:dictCount[key].count};
                }
            });
  
            //console.log(topFeatures);
            // how to send top features back to the frontend?
            //res.send({"name":"lol"});
            res.end('File uploaded');
  
          }
        } catch (e) {
          res.end('Error')
        }
      });
  });
  </code></pre>
  
  <p>My question is: Is there a way to return a json format data containing the most frequent word in this post request so I can do a set state in my react component and update the webpage? Thanks!</p>