I have set up a basic express server to accept some information submitted through a form. Unfortunately, I have run into some problems. I cannot log the data I receive onto the console. Can someone please help me figure this out?
app.js:
const express = require('express');
const path = require('path');
const app = express();
const port = 3000;
app.use(express.urlencoded({extended: false}));
app.use(express.static(path.join(__dirname,'public')));
app.use('/',(req,res,next) => {
res.sendFile(path.join(__dirname,'public','index.html'));
});
app.post('/api', (req, res) => {
console.log(req);
})
app.listen(port, () => console.log(`App is listening on port ${port}!`))
And here's the form itself: index.html:
<body>
<h1>Hello there!</h1>
<form id='form' method="POST" action="/api">
<input id='textField' type='text' name='name' placeholder='Enter your name'>
<p>Enter your date of birth:</p>
<div class='dob'>
<input id='date' type='number' name='date' placeholder='Date'>
<select id='dobMonth' name="month">
<option value="default">Month</option>
<option value="Jan">January</option>
<option value="Feb">February</option>
<option value="Mar">March</option>
<option value="April">April</option>
<option value="May">May</option>
<option value="June">June</option>
<option value="July">July</option>
<option value="Aug">August</option>
<option value="Sept">Septmeber</option>
<option value="Oct">October</option>
<option value="Nov">November</option>
<option value="Dec">December</option>
</select>
<input id='year' type='number' name='year' placeholder='Year'>
</div>
<input id='btn' type='submit'>
</form>
<script src='script.js'></script>
</body>
Thanks in advance :)