title: node.js express.js post data
body: <p>I encountered a problem in getting client POST data as follow:</p>
  
  <p>my client sent:</p>
  
  <pre><code>content-type:application/x-www-form-urlencoded
  </code></pre>
  
  <p>the content:</p>
  
  <pre><code>{"value":"123456"}
  </code></pre>
  
  <p>In node.js, it is no problem to parse the content to a json object, my code as follow:</p>
  
  <pre><code>http.createServer(function onRequest(request, response) {               
      request.setEncoding("utf8");
      var content = [];
  
      request.addListener("data", function(data) {
          content.push(data); //Collect the incoming data});
  
      //At the end of request call
      request.addListener("end", function() {
      response.writeHead( 200, {"Content-Type": "text/plain"} );
      ms = content[0];
      if(ms.toString() != "")
      {
          var msg = ms.toString();    //Parse the ms into string      
          console.log(msg); // Prints the message in the console
          var reqObj = JSON.parse(msg);   // If the incoming message is in JSON format, it can be parsed as JSON.
          console.log(reqObj); 
          response.end(); //Close the response
      }
  });
  </code></pre>
  
  <p>Output of the above code:
          {"account": "48264"}   //before parse to JSON
          { account: '48264' }   //after parse to JSON</p>
  
  <p>but when I changed into express.js and use bodyParser, it mixed up.</p>
  
  <pre><code>var express = require('express');
  var router = express.Router();
  
  /* GET users listing. */
  router.post('/', function(req, res, next) {
      req.setEncoding('utf8');
      console.log(req.body);
      console.log(req.body.value);
  });
  module.exports = router;
  </code></pre>
  
  <p>The above outputs in the console as follow:</p>
  
  <pre><code>{ "{\"account\": \"123456\"}": "" }
  undefined
  </code></pre>
  
  <p>I searched the web, but can't find the solution. please help.
  Thanks in advance</p>