req.body returns empty object when posting using form data in nodejs express
<p>I'm doing a post request to '/' with a simple text input and expecting to see the data entered in req.body.course. When console logging req.body.course, I am getting an empty object back. </p>

<p><strong>HTML</strong></p>

<pre><code>&lt;html&gt;
    &lt;head&gt;&lt;title&gt;New Course&lt;/title&gt;&lt;/head&gt;
    &lt;body&gt;
      &lt;form id="myform" action="/" method="post"&gt;
        &lt;input type="text" name="course" id="mytext" /&gt;
        &lt;input type="submit" id="mysubmit" /&gt;
      &lt;/form&gt;
    &lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p><strong>SERVER</strong></p>

<pre><code>var express = require('express');
var bodyParser = require('body-parser');

var app = express()
app.use(bodyParser.json())

app.set('views', __dirname + '/views');
app.engine('html', require('ejs').renderFile);
app.set('view engine', 'html');

app.post('/', function (req, res) {
    var course = req.body.course; 
    res.send(course);
});

app.get('/', function (req, res) {
    res.render('index');
});

app.listen(4000, function() {
    console.log("Server is listening on port", 4000);
});
</code></pre>

<p><strong>OUTPUT OF REQ.BODY</strong></p>

<pre><code>{}
</code></pre>