TypeError: Cannot read properties of undefined (reading 'abc')

Viewed 28

i have been working on a project in that first step I have to take input from a html file but failed to do so u have tried many times, but couldn't manage to solve the issue using body-parser.

 const axios = require("axios");
const express=require("express");
const bodyParser=require("body-parser");
const astrology=express();
astrology.use(bodyParser.urlencoded({extended: false}));
astrology.use(bodyParser.json());


astrology.get("/",function(_req,res){
    res.sendFile(__dirname +"/index.html");
})

    

astrology.post("/",function(res,req){
  const fname = req.body.abc;
  res.send('<h1>Hello</h1> '+fname')
 
})
astrology.listen(3000,function(){
  console.log("server is running at port 3000")
})
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>astrology</title>
</head>
<body>
    <h1>Astrology</h1>
    <form action="/" method="post">
    <input type="text" id="abc" name="abc">
    <input type="submit" name="submit">
    </form>
</body>
</html>

1 Answers

You have the order of the parameters wrong. The first argument is the request object, not the second one.

function(req, res) 
Related