I have a simple form:
<form method="POST">
<div class="form-group">
<label>Email address</label>
<input type="email" name="email" class="form-control" />
</div>
<div class="form-group">
<label>Password</label>
<input type="password" name="password" class="form-control" />
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
and I have a simple model:
const User = mongoose.model('User', {
email: {
type: String,
},
password: {
type: String,
}
});
and a simple post method
.post(async (req, res) => {
console.log(req.body);
const user = new User(req.body);
try {
const saveUser = await user.save();
res.send(saveUser);
} catch (error) {
res.send(error);
}
}
And yet, when i submit my form at the HTML file i get back an empty object.. i've tried every single one of SO solutions and none of them work for me.
NOTE: that i am using a JSON parser: app.use(express.json());
.
please help ?