title: How to convert form data (text/plain) to json with node?
body: <p>I need to execute a POST call to an API to placce an order. Herefore I made a simple Node js app. At the moment with this current state I receive text/plain data into our app, but this is not in JSON style.</p>
  
  <p>This is what I have now:</p>
  
  <pre><code>TypeOrder=buy
  Coin=BTC
  AmountCoin=1
  CoinPriceInEuro=100
  CoinAddress=17J6W29E2q94YNg5eiaHGsNWW9oJxsWu1M
  PaymentMethod=1
  GeneralTermsAccepted=true
  </code></pre>
  
  <p>I want it in JSON (like):</p>
  
  <pre><code>{
    "Email": "example1@1.nl",
    "Coin": "BTC",
    "CouponCode": "",
    "AmountEuro": 80.0,
    "AmountCoin": 1.0,
     "CoinPriceInEuro": 80,
    "CoinAddress": "17J6W29E2q94YNg5eiaHGsNWW9oJxsWu1M",
    "TypeOrder": "buy",
    "PaymentMethod": 1,
    "GeneralTermsAccepted": false
  }
  </code></pre>
  
  <p>And attached you find the code.</p>
  
  <p>Can anyone tell what I have to do in order to get it in right json?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>const express = require('express');
  const http = require('http');
  const app = express();
  const fs=require('fs');
  const hostname = '127.0.0.1';
  const port = 3000;
  const bodyParser = require('body-parser');
  var jsonParser = bodyParser.json()
  var urlencodedParser = bodyParser.urlencoded({ extended: false })
  
  fs.readFile('index.html', (err, html) =&gt; {
   if(err) {
       throw err;
   }
  
   var server = http.createServer((req, res) =&gt; {
       res.statusCode=200;
       res.setHeader('Content-type', 'text/html');
       res.write(html);
       res.end();
   });
  
   server.listen(port, hostname, () =&gt; {
       console.log('Server started on port'+port);
   });
  
   // POST /login gets urlencoded bodies
          app.post('http://localhost:3030/rest/v1/PostOrder', urlencodedParser, function (req, res) {
              console.log(req.body);
              if (!req.body) return res.sendStatus(400);
              res.send('http://localhost:3030/rest/v1/PostOrder', {qs:req.query});
          });
  });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;body&gt;
  
  &lt;form enctype="text/plain" action="http://localhost:3030/rest/v1/PostOrder" method="POST"&gt;
    Buy/Sell:&lt;br&gt;
    &lt;input type="text" name="TypeOrder" value="buy"&gt;
    &lt;br&gt;
    Coin:&lt;br&gt;
    &lt;input type="text" name="Coin" value="BTC"&gt;
  
    Amount in Coin:&lt;br&gt;
    &lt;input type="number" name="AmountCoin" value="1"&gt;
    &lt;br&gt;
    Coin Price in Euro:&lt;br&gt;
    &lt;input type="number" name="CoinPriceInEuro" value="100"&gt;
    &lt;br&gt;
    Coin address to send:&lt;br&gt;
    &lt;input type="text" name="CoinAddress" value="17J6W29E2q94YNg5eiaHGsNWW9oJxsWu1M"&gt;
    &lt;br&gt;
    Payment method:&lt;br&gt;
    &lt;input type="radio" name="PaymentMethod" value="1" checked&gt; iDeal&lt;br&gt;
    &lt;input type="radio" name="PaymentMethod" value="2"&gt; Credit Card&lt;br&gt;
    &lt;input type="radio" name="PaymentMethod" value="3"&gt; PayPal&lt;br&gt;
    &lt;br&gt;
    Terms accepted:&lt;br&gt;
    &lt;input type="radio" name="GeneralTermsAccepted" value="true" checked&gt;Ja&lt;br&gt;
    &lt;input type="radio" name="GeneralTermsAccepted" value="false"&gt;No&lt;br&gt;
    &lt;br&gt;&lt;br&gt;
  
  
    &lt;input type="submit" value="Submit"&gt;
  &lt;/form&gt;
  
  &lt;p&gt;If you click the "Submit" button, the form-data will be sent to a page called "/action_page.php".&lt;/p&gt;
  
  &lt;/body&gt;
  &lt;/htm</code></pre>
  </div>
  </div>
  </p>