title: Form not sending data via _POST
body: <p>It's meant to be a basic web form but I am having issues with it. I have spent hours working on it but can't seem to find the problem.</p>
  <p>I am getting the error message <code>Cannot destructure property 'email' of 'req.body' as it is undefined</code>. The full source code can be found here: <a href="https://github.com/SophalLee/project_06_sophal_lee" rel="nofollow noreferrer">https://github.com/SophalLee/project_06_sophal_lee</a>. Here are snippets of my code:</p>
  <p>index.js</p>
  <pre><code>app.post('/login', (req, res) =&gt; {
      const { email, password } = req.body;
      console.log(email);
  })
  </code></pre>
  <p>login-form.js</p>
  <pre><code>import { checkName, numbersAndSpaceCheck, emailCheck } from '/js/validation.js';
  
  const loginForm = document.getElementById('login');
  const email = document.getElementById('email');
  const password = document.getElementById('password');
  
  loginForm.addEventListener('submit', (e) =&gt; {
      e.preventDefault();
      if(checkInputs()) {
          loginForm.submit();
      }
  });
  
  /* Validate input from form */
  function checkInputs() {
      const emailValue = email.value.trim();
      const passwordValue = password.value.trim();
  
      let emailSuccess = false;
      let passwordSuccess = false;
  
      if(emailValue === '') {
          setErrorFor(email, &quot;Email cannot be blank&quot;);
          emailSuccess = false;
      }
      else if(!emailCheck(emailValue)) {
          setErrorFor(email, &quot;Invalid email&quot;);
          emailSuccess = false;
      }
      else {    
          setSuccessFor(email);
          emailSuccess = true;
      }
  
      if(passwordValue === '') {
          setErrorFor(password, &quot;Password cannot be blank&quot;);
          passwordSuccess = false;
      }
      else {
          setSuccessFor(password);
          passwordSuccess = true;
      }
  
      return (emailSuccess &amp; passwordSuccess);
  }
  
  /* Display error message and error icon */
  export function setErrorFor(input, message) {
      const formControl = input.parentElement;
      const error = formControl.querySelector('.error-message');
  
      error.className = 'error-message error';
      error.innerText = message;
      formControl.className = 'form-control error'; 
  }
  
  /* Display success icon and remove any error message */
  export function setSuccessFor(input) {
      const formControl = input.parentElement;
      const error = formControl.querySelector('.error-message');
      error.className = 'error-message';
      formControl.className = 'form-control success';
  }
  </code></pre>
  <p>login.ejs</p>
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang=&quot;en&quot;&gt;
  &lt;head&gt;
      &lt;meta charset=&quot;UTF-8&quot;&gt;
      &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge&quot;&gt;
      &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;
      &lt;script src=&quot;https://kit.fontawesome.com/cf53bba659.js&quot; crossorigin=&quot;anonymous&quot;&gt;&lt;/script&gt;
      &lt;link href=&quot;/css/forms.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;/&gt;
      &lt;script type=&quot;module&quot; src=&quot;/js/login-form.js&quot; defer&gt;&lt;/script&gt;
      &lt;title&gt;Locations - Login&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;div class=&quot;container&quot;&gt;
          &lt;div class=&quot;header&quot;&gt;
              &lt;h1&gt;Login&lt;/h1&gt;
          &lt;/div&gt;
          &lt;form class=&quot;form&quot; id=&quot;login&quot; action=&quot;/login&quot; method=&quot;POST&quot; novalidate&gt;
              &lt;div class=&quot;form-control&quot;&gt;
                  &lt;label for=&quot;email&quot;&gt;Email&lt;/label&gt;
                  &lt;input name=&quot;email&quot; id=&quot;email&quot; type=&quot;text&quot; required&gt;
                  &lt;i class=&quot;fas fa-check-circle&quot;&gt;&lt;/i&gt;
                  &lt;i class=&quot;fas fa-exclamation-circle&quot;&gt;&lt;/i&gt;
                  &lt;div class=&quot;error-message&quot;&gt;&amp;nbsp;&lt;/div&gt;
              &lt;/div&gt;
              &lt;div class=&quot;form-control&quot;&gt;
                  &lt;label for=&quot;password&quot;&gt;Password&lt;/label&gt;
                  &lt;input name=&quot;password&quot; id=&quot;password&quot; type=&quot;password&quot; required&gt;
                  &lt;i class=&quot;fas fa-check-circle&quot;&gt;&lt;/i&gt;
                  &lt;i class=&quot;fas fa-exclamation-circle&quot;&gt;&lt;/i&gt;
                  &lt;div class=&quot;error-message&quot;&gt;&amp;nbsp;&lt;/div&gt;
              &lt;/div&gt;
              &lt;button&gt;Submit&lt;/button&gt;
          &lt;/div&gt;
          &lt;/form&gt;
      &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>