var express = require('express');
var router = express.Router();
var MongoClient = require('mongodb').MongoClient
/* GET home page. */
router.get('/', function(req, res, next) {
res.render('index',{title: 'Express'});
});
router.post('/submit',function(req, res) {
console.log(req.body)
MongoClient.connect('mongodb://localhost:27017/',function(err,client){
if(err)
console.log('error')
else
console.log('Database connected')
})
res.send('Form submitted successfully');
});
module.exports = router;
Error showing in the terminal like below while submitting a form,
terminal
I submitted a form and want to show that submitted data in terminal with console.log(req,body)
but it also need to connect with mongodb and show in terminal like “Database connected” if there have any problem then “error”. But it showing kind of error in node_modules/mongodb/lib/cmap/connect.js:268:44
New contributor
K Arun is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.