title: Formidable returns TypeError, ERR_INVALID_ARG_TYPE: The "path" argument is undefined
body: <p>I'm having trouble uploading files using formidable. I'm on Windows server 2016.</p>
  <p>My code, which in its entirely is shown below, is based on <a href="https://www.geeksforgeeks.org/how-to-upload-file-using-formidable-module-in-node-js/" rel="nofollow noreferrer">https://www.geeksforgeeks.org/how-to-upload-file-using-formidable-module-in-node-js/</a></p>
  <pre><code>const express = require('express');
  const fs = require('fs');
  const path = require('path')
  const formidable = require('formidable');
     
  const app = express();
     
  app.post('/api/upload', (req, res, next) =&gt; {
      
      const form = new formidable.IncomingForm(
          { uploadDir: __dirname + '\\tmp',  keepExtensions: true }
      );
      form.parse(req, function(err, fields, files){
          var oldPath = files.profilePic.path;
          var newPath = path.join(__dirname, 'uploads')
                  + '/'+files.profilePic.name
          var rawData = fs.readFileSync(oldPath)
        
          fs.writeFile(newPath, rawData, function(err){
              if(err) console.log(err)
              return res.send(&quot;Successfully uploaded&quot;)
          })
    })
  });
     
  app.listen(3000, function(err){
      if(err) console.log(err)
      console.log('Server listening on Port 3000');
  });
  </code></pre>
  <p>I use Postman to send a file.</p>
  <p>When triggering the <code>/api/upload</code> API, the file sent is correctly placed in the tmp folder, but reading the path is when the problem arise:</p>
  <pre><code>TypeError [ERR_INVALID_ARG_TYPE]: The &quot;path&quot; argument must be of type string or an instance of Buffer or URL. Received undefined
  </code></pre>
  <p>This message points to <code>fs.readFileSync(oldPath)</code>.</p>
  <p><code>console.log('files='+files)</code> returns <code>files=[object Object]</code></p>
  <p><code>console.log('files.profilePic='+files.profilePic)</code> returns</p>
  <pre><code>C:\somepath\node_modules\formidable\src\PersistentFile.js:50
      return `PersistentFile: ${this._file.newFilename}, Original: ${this._file.originalFilename}, Path: ${this._file.filepath}`;
                                           ^
  
  TypeError: Cannot read properties of undefined (reading 'newFilename')
      at PersistentFile.toString (C:\somepath\node_modules\formidable\src\PersistentFile.js:50:42)
  </code></pre>
  <p>All 4 referenced modules exist in node_modules folder.</p>