Why cant i grab my html form req body?

I am using create-react-app and every thing is up to date but when i try and console.log the req.body i get nothing and when i try res.json(req.body) i get an empty object i should also mention that i am using a proxy for the server since create-react-app listens on another port for live updates, the code is as follows…

server.js

const express = require('express');
const app = express();

app.use(express.json({ extended: false }));

app.use('/mail', require('./routes/mail'));

const PORT = process.env.PORT || 8080;

app.listen(PORT, () => console.log(`Listening on port ${PORT}...`));

routes/mail.js (route)

const express = require('express');
const router = express.Router();
// const nodemailer = require('nodemailer');
require('dotenv').config();

router.post('/', (req, res) => {
  console.log(req.body);
  res.send('this works');
});

module.exports = router;

Contact.js (react component where the form is)

import React, { useState } from 'react';

const Contact = () => {
  const [name, setName] = useState('');
  const [phone, setPhone] = useState('');
  const [msg, setMsg] = useState('');
  const clear = e => {
    setName('');
    setPhone('');
    setMsg('');
    e.preventDefault();
  };

  return (
    <section className='contact-section' id='contact'>
      <h4>Connect With Me Below</h4>
      <form action='/mail' method='POST'>
        <div className='form-group'>
          <div className='form-input'>
            <label htmlFor='name'>Name</label>
            <input
              type='text'
              name='name'
              value={name.value}
              onChange={setName}
            />
          </div>
          <div className='form-input'>
            <label htmlFor='phone'>Phone</label>
            <input
              type='text'
              name='phone'
              value={phone.value}
              onChange={setPhone}
            />
          </div>
        </div>
        <div className='form-input'>
          <label htmlFor='msg'>Message</label>
          <textarea
            type='text'
            name='msg'
            value={msg.value}
            onChange={setMsg}
          />
        </div>
        <input type='submit' value='Connect' onSubmit={clear} />
      </form>
    </section>
  );
};

export default Contact;

you need body-parser

Are you parsing the incoming request?
I don’t see any.

Have a look at express body-parser

If you take a look at the first bit of code you see app.use(express.json) that is body parser it is a core middleware now with then 4.14 and up version I believe. I also figured it out late last night after posting this question so just for me the purpose of answering this for anyone else who may have a similar issue the reason why this didn’t work is because I was attempting to parse json when I needed to parse the encoded data from the html form so rather than using express.json I needed to use express.urlencoded({extended:false}).

I’ve posted the answer inside a reply to another post if you’d like to see a full explanation but app.use(express.json) is the body parser.