Search code examples
node.jsexpressexpress-handlebars

Cannot read form input value | nodejs | express | express-handlebars


I tried to receive the input value from the user through form request using express handlebars. I get the following error.

TypeError: Cannot read property 'personname' of undefined

The following pictures contain the code snippets

index.js home.handlebars

Please Help me to resolve the issue


Solution

  • Express won't parse req.body for you by default. You need middleware, preferably body-parser

    const app = require('express')()
    const bodyparser = require('body-parser')
    
    app.use(bodyparser.json());
    app.use(bodyparser.urlencoded({extended: true}));