title: toString undefined in app.js main file - NodeJS
body: <p>I am trying to get the filename of the uploaded file but I am getting error while doing string manipulation like below in main app file of nodejs:</p>
  
  <pre><code>var fileName = file.split('path:')[1]
      .split('\',')[0]
      .split(dir)[1]
      .toString()
      .replace(/\\/g, '')
      .replace(/\//g, '');
  </code></pre>
  
  <p>I get error at <code>.toString()</code>, not sure why.</p>
  
  <h1>error stacktrace</h1>
  
  <pre><code>TypeError: Cannot read property 'toString' of undefined
      at C:\Users\murli\NodeProjects\SpeechExpress\app.js:57:76
      at IncomingForm.&lt;anonymous&gt; (C:\Users\murli\NodeProjects\SpeechExpress\node_modules\formidable\lib\incoming_form.js:105:9)
      at emitNone (events.js:86:13)
      at IncomingForm.emit (events.js:185:7)
      at IncomingForm._maybeEnd (C:\Users\murli\NodeProjects\SpeechExpress\node_modules\formidable\lib\incoming_form.js:553:8)
      at C:\Users\murli\NodeProjects\SpeechExpress\node_modules\formidable\lib\incoming_form.js:230:12
      at WriteStream.&lt;anonymous&gt; (C:\Users\murli\NodeProjects\SpeechExpress\node_modules\formidable\lib\file.js:74:5)
      at WriteStream.g (events.js:291:16)
      at emitNone (events.js:91:20)
      at WriteStream.emit (events.js:185:7)
  </code></pre>
  
  <h1>code</h1>
  
  <pre><code>app.use('/uploadFile', function(request, response){
  
       // parse a file upload
      var mime = require('mime');
      var formidable = require('formidable');
      var util = require('util');
  
      var form = new formidable.IncomingForm();
  
      var dir = !!process.platform.match(/^win/) ? '\\public\\uploads\\' : '/public/uploads/';
  
      form.uploadDir = __dirname + dir;
      console.log("Test 99: " + form.uploadDir);
      form.keepExtensions = true;
      form.maxFieldsSize = 10 * 1024 * 1024;
      form.maxFields = 1000;
      form.multiples = false;
      console.log("Test 100: ");
  
      form.parse(request, function(err, fields, files) {
  
          var file = util.inspect(files);
          console.log("form parse file: "+file + "\n" + files);
  
          response.writeHead(200, getHeaders('Content-Type', 'application/json'));
  
  
          var fileName = file.split('path:')[1].split('\',')[0].split(dir)[1].toString().replace(/\\/g, '').replace(/\//g, '');
          var fileURL = 'http://' + app.address + ':' + port + '/public/uploads/' + fileName;
  
          console.log('fileURL: ', fileURL);
  
          response.write(JSON.stringify({
              fileURL: fileURL
          }));
  
          response.end();
      });
  
  });
  </code></pre>
  
  <h1>file contents</h1>
  
  <pre><code>{ file:
     File {
       domain: null,
       _events: {},
       _eventsCount: 0,
       _maxListeners: undefined,
       size: 114898,
       path: 'C:\\Users\\username\\NodeProjects\\SpeechExpress\\public\\uploads\\upload_3c927e85105d0fd5d873e84952821531.webm',
       name: '1234.webm',
       type: 'video/webm',
       hash: null,
       lastModifiedDate: 2017-09-19T22:18:03.330Z,
       _writeStream:
        WriteStream {
          _writableState: [Object],
          writable: false,
          domain: null,
          _events: {},
          _eventsCount: 0,
          _maxListeners: undefined,
          path: 'C:\\Users\\username\\NodeProjects\\SpeechExpress\\public\\uploads\\upload_3c927e85105d0fd5d873e84952821531.webm',
          fd: null,
          flags: 'w',
          mode: 438,
          start: undefined,
          autoClose: true,
          pos: undefined,
          bytesWritten: 114898,
          closed: true } } }
  </code></pre>
  
  <p>All I need is this </p>
  
  <p><code>upload_3c927e85105d0fd5d873e84952821531.webm</code></p>
  
  <p>from this</p>
  
  <p><code>C:\\Users\\username\\NodeProjects\\SpeechExpress\\public\\uploads\\upload_3c927e85105d0fd5d873e84952821531.webm</code></p>