title: Getting http post form data in Node.JS
body: <p>Hey I am trying to send the post request using express and node and here is my code.</p>
  
  <p>index.html</p>
  
  <pre><code>&lt;html&gt;
  
  &lt;head&gt;
      &lt;title&gt;Test&lt;/title&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
      &lt;form action="/form" method="POST" enctype="multipart/form-data"&gt;
          &lt;input type="text" name="imagename"&gt;&lt;/input&gt;
          &lt;input type="submit" name="submit" value="submit"&gt;&lt;/input&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p>My app.js file is given below:</p>
  
  <pre><code>var express = require('express');
  var app = express();
  var bodyParser = require('body-parser');
  
  app.use(bodyParser.urlencoded({
     extended: true
  }));
  app.use(bodyParser.json());
  
  app.post('/form', function(req, res){
   res.setHeader('Content-Type', 'application/json');
   setTimeout(function(){
       res.send(JSON.stringify({
          imagename: req.body.imagename || null
  
      }));
    }, 1000);
  });
  </code></pre>
  
  <p>Now I should get the output as imagename: //value added in the form if true or else null. And I am always getting a null value. I tried to log the value of req.body.imagename and I am getting undefined instead of the value that I inserted in the form. Any help would be appretiated.</p>