0

I have a HTML file served from my NodeJS server, where I am trying to pass the details of the form to the backend. But for some weird reason on making the POST request, I am not getting any body. Whenever I am printing the req.BODY in my console, all I am getting is undefined.

The HTML page-

<form action="/login" method="POST">
    <div class="container-fluid ">
        <div class="row">
            <div class="col-md-3"></div>
            <div class="col-md-6 bg-light p-5">
                <div class="row">
                    <div class="col-md-3"></div>
                    <div class="form-group col-md-6">
                        <label class="form-label col-label" for="fname">First Name</label>
                        <input class="field__input" type="text" name="fname" placeholder="" id="#fname">
                    </div>
                    <div class="col-md-3"></div>
                    <div class="col-md-3"></div>
                    <div class="form-group col-md-6">
                        <label class="form-label col-label" for="lname">Last Name</label>
                        <input class="field__input" type="text" name="lname" placeholder="" id="#lname">
                    </div>
                    <div class="col-md-3"></div>
                    <div class="col-md-3"></div>
                    <div class="form-group col-md-6">
                        <label class="form-label col-label my-3" for="email">Email Address</label>
                        <input class="field__input" type="text" name="email" placeholder="joe.black@gmail.com" id="#email">
                    </div>
                    <div class="col-md-3"></div>
                    <div class="col-md-3"></div>
                    <div class="form-group col-md-6">
                        <label class="form-label col-label" for="pass">Password </label>
                        <input class="field__input" type="password" name="pass" placeholder="" id="#pass">
                    </div>
                    <div class="col-md-3"></div>

                </div>
                <div class="form-group text-center">
                    <input id="#create" type="submit" value="Create" class="btn btn-outline-dark" >
                </div>
            </div>
            <div class="col-md-3"></div>
        </div>
    </div>
    </form>

My NodeJS route-


router.post('/login', async (req, res) => {
    // const user = User(req.body);
    try {
        console.log(req.body);
        res.status(201).send({});
    } catch (e) {
        console.log(e);
        res.status(500).send('ERROR');
    }
});

All my terminal is printing is

undefined

Where am I going wrong?

imharjyotbagga
  • 199
  • 4
  • 17

0 Answers0