this my controller
//...
if (req.method == 'POST') {
try {
//..
console.log(req.body.customerName);
}
I was trying to see if the req.body returned data but it returned undefined
this my route
var express = require('express');
var router = express.Router()
//...
router.get('/add-bill',check_login.yeu_cau_dang_nhap, billController.addBill);
router.post('/add-bill',check_login.yeu_cau_dang_nhap, billController.addBill);
//use body-parser in app.js
var app = express();
//...
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json());
//...
i tried installing "body-parser" library but it doesn't work
To parse mutlipart-form You've to install
multer, for other body typesbody-parserIf Your form sends only text fields then change
enctype="application/x-www-form-urlencoded"in form tag and no need formultercausebody-parserworks perfect with nonmultipartenctype.But if Your form has file input, then You've to use
multer.2 solutions:
multer.none()at parent level:also, create
getBillmethod inbillControllerand don't usereq.method === 'POST'cause You're already doing byrouter.post