I am unable to set the values of HTML form inputs on to my Node JS variable. Below is my JS code where I am not able to set the values of variables "hostname" and "port" which will in turn concatenate to a new variable called url.
console.log(url) prints just mongodb://:. which suggests that my HTML form values are not being stored in my Node JS variables.
var express = require('express'); // call express
var app = express(); // define our app using express
var bodyParser = require('body-parser');
var router = express.Router();
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
var port = process.env.PORT || 8080;
var router = express.Router();
const dbname = "admin";
var hostname ='';
var port2 ='';
app.post('/', function(req, res){
hostname = req.body.hostname;
port2 = req.body.port2;
});
var url ="mongodb://"+hostname+":"+port2;
Below is my html which is handling the form inputs
<form class="clr-form" action="/" method="POST">
<input type="text" name="hostname" placeholder="Enter Host Name" class="clr-input"> <br/>
<input type="text" name="port2" placeholder="Enter Port" class="clr-input"><br/>
<input type="submit" value="Submit" />
</form>