title: nodejs formidable async issue
body: <p>I'm working on a nodejs app using the formidable 3rd party module. And I'm trying to get global scope access (see var formfields, below) to the webform fields returned by the form.parse method below. First, form.parse is an asynch operation and per the module docs here: <a href="https://github.com/felixge/node-formidable" rel="nofollow noreferrer">https://github.com/felixge/node-formidable</a> is designed to take a callback. I'm doing that, see the anonymous function passed to form.parse.</p>
  
  <p>My problem is, no matter what I do I can't get form.parse to properly return the fields object to the formfields variable in global context/scope. I've tried (for days) various combinations of callback functions and closures which return secondary functions, etc. But no luck. </p>
  
  <p>The basic thing I'm trying to do is: </p>
  
  <pre><code>var form = new formidable.IncomingForm();
  form.encoding = 'utf-8';
  var formfields = form.parse(req, function (err, fields, files) {
    console.log("within form.parse method, subject field of fields object is: " + fields.subjects);
    return fields;
  }); // form.parse
  
  console.log("type of formfields is: " + typeof formfields);
  console.log("subject field of formfields object is: " + formfields.subjects);
  </code></pre>
  
  <p>But as you'll see from the console.log output below, even though I'm using a callback, execution is "falling thru" to the last 2 console.log lines of code -- before running the console.log line within form.parse or properly returning "fields" from form.parse and assigning it to 'var formfields'. </p>
  
  <p>Specifically the console.log output shows form.parse returns an object (fields) to become formfields. But it lacks the actual form data (e.g. formfields.subjects) which log as undefined. The last line of output shows form.parse is grabbing the form data (fields.subjects, which logs as "biology") but not properly returning it to become 'var formfields'. </p>
  
  <pre><code>type of formfields is: object
  subject field of formfields object is: undefined
  within form.parse method, subject field of fields object is: biology
  </code></pre>
  
  <p>I don't <em>have</em> to have a solution to this as I have the option to just access and manipulate the field data from within form.parse. But I have various things to do with that form data (a db query, results formatting, return to client) and they'd all have to be done nested within form.parse. It's doable but makes for awkward code. I was hoping for a solution to my question as it would make for cleaner code. Thanks in advance for any assistance.</p>