How to fix TypeError: Cannot read property 'name' from Express Nodemailer
app.use(express.bodyParser());
add that to your app.jsthat's what grabs information from the post data form.
You have to require body parser package for this.
At first you have to install it with npm.
$ npm install --save body-parser
Then require that in your js file.
var bodyParser = require('body-parser');
Then add the parser. As you are using html post method it uses urlencoded
as encoding type. For that add this line.
var urlencodedParser = bodyParser.urlencoded({ extended: false });
(If you use json you must use bodyParser.json()
instead of this)
Now add the parser with the encoding type to app.post
method as follows.
app.post('/',urlencodedParser, function (req, res) { //your code here});
You don't have to be explicitly mention any bodyParser or bodyParer.json
Instead You can make it simple to use this because this is a built-in middleware function in Express.
app.use(express.json());