When I click Submit to post the entry on MongoDB, it gives me this error
MongoDB is connected to the server as well.
This is my router file
const express = require('express');
const Club = require('../models/club')
const Router = express.Router();
Router.get('/', (eror,res)=>{
res.render('index')
})
Router.post('/form', (req,res)=>{
const name = req.body.name;
console.log(name);
})
module.exports = Router;
This is my form
<form action="/form" method="post">
<input type="text" name="name" placeholder="Add an Entry">
<input type="submit" value="Submit">
</form>
I tried everything, but it wont work
3
Answers
We have to add middleware to parse request body. In your case:
Depending on your Express version, you might need to use use the
bodyParser
middleware before your handlersIn your app.js file you need to add a middleware to parse the data, you don’t need to install bodyParser at the current express version they already integrated this feature, you just need to add this: