title: Getting TypeError: Cannot read property 'content-length' of undefined When Using Node.js Formidable
body: <p>I'm trying to console.log a number I type in an input using formidable. I am getting an error that says <code>TypeError: Cannot read property 'content-length' of undefined</code>. I have tried to add a <code>fs.readFile</code> into the code and it won't work.</p>
  <p><strong>Here is my app.js</strong></p>
  <pre><code>const express = require('express');
  const http = require('http');
  const formidable = require('formidable');
  const fs = require('fs');
  const ejs = require('ejs');
  const path = require('path');
  const multer = require('multer');
  const upload = multer({ dest: 'upload/'});
  const type = upload.fields([{ name: 'gradeNumber', maxCount: 10 }]);
  const app = express();
  app.use(express.static(__dirname + '/public'));
  app.set('view engine', 'ejs');
  
  
  
  app.get('/fileupload', function (req, res) {
      res.render(&quot;upload&quot;)
  });
      
  
  
  app.post('/fileupload', function (req, res) {
      const form = new formidable.IncomingForm();
      form.parse(function (err, fields, files) {
          console.log(fields.gradeNumber);
          const oldpath = files.filetoupload.path;
          const newpath = 'C:/Users/Shubh Computer/Desktop/VSCode/Grades/1/' + files.filetoupload.name;
          fs.rename(oldpath, newpath, function (err) {
              if (err) throw err; 
              res.write('File uploaded and moved!');
              res.end();
          });
      });
  });
  app.listen(3000);
  </code></pre>
  <p><strong>upload.ejs</strong></p>
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  
  &lt;head&gt;
      &lt;title&gt;Upload File&lt;/title&gt;   
  &lt;/head&gt;
  
  &lt;body&gt;
      
      &lt;form action=&quot;fileupload&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot;&gt;
          &lt;input type=&quot;file&quot; name=&quot;filetoupload&quot;&gt;&lt;br&gt;
          
          &lt;label&gt;What Grade&lt;/label&gt;&lt;input type=&quot;text&quot; name=&quot;gradeNumber&quot;&gt;&lt;br&gt;
          &lt;input type=&quot;submit&quot;&gt;
      &lt;/form&gt;
  &lt;/body&gt;
                                                                              
  &lt;/html&gt;
  </code></pre>
  <p>I'm trying to log the input with the name &quot;gradeNumber&quot;. If somebody could help me I will be very grateful because I've gotten very frustrated with this.</p>