title: how to read text file from POST with express-uploadfile?
body: <p>I am trying to make node js server, for uploading text files there.</p>
  
  <p>so I am using POST for get local user's text file, then I want to make server read the file.</p>
  
  <p>I think I can make user upload he's local text file, I can get uploaded file's description.</p>
  
  <p>but It is hard to make server read the file's actual string.
  because I always get 'undefined' when I get try to read it by
  <code>logFile.data.toString('utf8');</code></p>
  
  <p>Could you guide me how to read the uploaded text file's string?</p>
  
  <p>Here is my tried code, Thank you.:</p>
  
  <p>html:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
      &lt;meta charset="UTF-8"&gt;
      &lt;title&gt;Document&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;h3&gt;ENTER&lt;/h3&gt;
  &lt;form action="/loadfile" method="post" enctype="multipart/form-data"&gt;
      &lt;table&gt;
  
          &lt;tr&gt;
              &lt;td&gt;file : &lt;/td&gt;
              &lt;td&gt;&lt;input type="file" name="fileName"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;input type="submit" value="submit"&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
  &lt;/form&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  
  </code></pre>
  
  <p>logFile is a file from POST. 
  I think logFile.data returns the byte array of its text file contents,
  so I tried to convert to String by toString('utf8') or toString().</p>
  
  <p>This is node js server:</p>
  
  <pre><code>var fileupload = require("express-fileupload");
    app.use(fileupload());
    app.use(bodyParser.urlencoded({extended: false}));
  
             (fetching html... )
  
  app.post('/loadfile', (req,res) =&gt;{
  
        console.log("react to post action - loadFile");
        res.send("submit ok");
          var logFile = req.files;
  
          console.log(logFile);
          var buffer = logFile.data;
          console.log(buffer.toString('utf8'));
  
      });
  
  
  
  </code></pre>
  
  <p>when I put "test.txt" files to this html, this is server's console reaction.</p>
  
  <pre><code>
  2020-02-14T08:18:50.909771+00:00 app[web.1]: react to post action - loadFile
  2020-02-14T08:18:50.912904+00:00 app[web.1]: {
  2020-02-14T08:18:50.912905+00:00 app[web.1]: fileName: {
  2020-02-14T08:18:50.912906+00:00 app[web.1]: name: 'test.txt',
  2020-02-14T08:18:50.912907+00:00 app[web.1]: data: &lt;Buffer 68 65 6c 6c 6f 20 74
  68 69 73 20 69 73 20 74 65 73 74 20 74 65 78 74 20 66 69 6c 65&gt;,
  2020-02-14T08:18:50.912907+00:00 app[web.1]: size: 28,
  2020-02-14T08:18:50.912908+00:00 app[web.1]: encoding: '7bit',
  2020-02-14T08:18:50.912908+00:00 app[web.1]: tempFilePath: '',
  2020-02-14T08:18:50.912912+00:00 app[web.1]: truncated: false,
  2020-02-14T08:18:50.912912+00:00 app[web.1]: mimetype: 'text/plain',
  2020-02-14T08:18:50.912913+00:00 app[web.1]: md5: 'f4e8dbc8c1fa4d01329d4f8260511
  1d2',
  2020-02-14T08:18:50.912913+00:00 app[web.1]: mv: [Function: mv]
  2020-02-14T08:18:50.912914+00:00 app[web.1]: }
  
  ** I can see the uploaded file's information properly **
  
  2020-02-14T08:18:50.912914+00:00 app[web.1]: }
  2020-02-14T08:18:50.914538+00:00 app[web.1]: TypeError: Cannot read property 'to
  String' of undefined
  2020-02-14T08:18:50.914539+00:00 app[web.1]: at /app/server.js:111:28
  2020-02-14T08:18:50.914540+00:00 app[web.1]: at Layer.handle [as handle_request]
   (/app/node_modules/express/lib/router/layer.js:95:5)
  2020-02-14T08:18:50.914540+00:00 app[web.1]: at next (/app/node_modules/express/
  lib/router/route.js:137:13)
  2020-02-14T08:18:50.914541+00:00 app[web.1]: at Route.dispatch (/app/node_module
  s/express/lib/router/route.js:112:3)
  2020-02-14T08:18:50.914541+00:00 app[web.1]: at Layer.handle [as handle_request]
   (/app/node_modules/express/lib/router/layer.js:95:5)
  2020-02-14T08:18:50.914541+00:00 app[web.1]: at /app/node_modules/express/lib/ro
  uter/index.js:281:22
  2020-02-14T08:18:50.914542+00:00 app[web.1]: at Function.process_params (/app/no
  de_modules/express/lib/router/index.js:335:12)
  2020-02-14T08:18:50.914542+00:00 app[web.1]: at next (/app/node_modules/express/
  lib/router/index.js:275:10)
  2020-02-14T08:18:50.914542+00:00 app[web.1]: at urlencodedParser (/app/node_modu
  les/body-parser/lib/types/urlencoded.js:100:7)
  2020-02-14T08:18:50.914543+00:00 app[web.1]: at Layer.handle [as handle_request]
   (/app/node_modules/express/lib/router/layer.js:95:5)
  
  **But read the file's actual string by 'toString()' is not possible, why??**
  
  </code></pre>