title: How do I get data from form fields without Express?
body: <p>I am trying to get the data from a form's fields in a POST request. My problem is that the object that I am getting that should contain the data is empty when I use the browser, but it works if I am using Postman. </p>
  
  <p>I am using the <a href="https://www.npmjs.com/package/formidable" rel="nofollow noreferrer">formidable</a> module to get the data from the form.</p>
  
  <p>Here is my form:</p>
  
  <pre><code>&lt;div class="form"&gt;
    &lt;form action="/signup" method="POST"&gt;
      &lt;div class="form-group"&gt;
        &lt;label for="username"&gt;Username:&lt;/label&gt;
        &lt;input type="text" class="form-control" id="username" placeholder="Username"&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
        &lt;label for="email"&gt;Email:&lt;/label&gt;
        &lt;input type="email" class="form-control" id="email" placeholder="Email"&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
        &lt;label for="password"&gt;Password:&lt;/label&gt;
        &lt;input type="password" class="form-control" id="password" placeholder="Password"&gt;
      &lt;/div&gt;
      &lt;button type="submit" class="btn btn-default" id="signup-btn"&gt;Sign Up&lt;/button&gt;
    &lt;/form&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Here is the route I for the form:</p>
  
  <pre><code>signupPost: function (request) {
    route.post('/signup', function () {
      var form = new formidable.IncomingForm();
  
      form.parse(request, function (error, fields, files) {
        if (error) {
          console.error(error);
        }
        console.log(request.headers);
        console.log(fields);
      });
    });
  }
  </code></pre>
  
  <p>The <code>route.post</code> function is a custom function declared in a different module:</p>
  
  <pre><code>post: function (url, handler) {
    if (this.request.method === 'POST' &amp;&amp; this.request.url === url) {
      var data = handler();
      this.response.end(data);
    }
  }
  </code></pre>
  
  <p>I have tried changing the headers so that the <code>post</code> function looks like this, but it didn't work:</p>
  
  <pre><code>post: function (url, handler) {
    if (this.request.method === 'POST' &amp;&amp; this.request.url === url) {
      this.response.writeHead(200, {
        'content-type': 'multipart/form-data'
      });
      var data = handler();
      this.response.end(data);
    }
  }
  </code></pre>
  
  <p>Incase it helps, here are the headers I get back from the browser:</p>
  
  <pre><code>{ host: 'localhost:8080',
    connection: 'keep-alive',
    'content-length': '0',
    'cache-control': 'max-age=0',
    origin: 'http://localhost:8080',
    'upgrade-insecure-requests': '1',
    'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36',
    'content-type': 'application/x-www-form-urlencoded',
    accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
    referer: 'http://localhost:8080/signup',
    'accept-encoding': 'gzip, deflate, br',
    'accept-language': 'en-US,en;q=0.8' }
  </code></pre>
  
  <p>And here are the ones from Postman:</p>
  
  <pre><code>{ 'cache-control': 'no-cache',
    'postman-token': '72c9c23c-dc66-400e-85cb-615a633efd02',
    'content-type': 'multipart/form-data; boundary=--------------------------641553275315430252355922',
    'user-agent': 'PostmanRuntime/6.2.5',
    accept: '*/*',
    host: 'localhost:8080',
    'accept-encoding': 'gzip, deflate',
    'content-length': '409',
    connection: 'keep-alive' }
  </code></pre>
  
  <p>I have the project <a href="https://github.com/calebkleveter/Burdoc" rel="nofollow noreferrer">on GitHub</a> if anyone wants to see the whole project.</p>