title: Express.js req.body.variableName returning undefined
body: <p>I'm working on a website using Node.js with Express and EJS as the templating engine, and I'm having trouble getting data from the form on the site. Here is my code:</p>
  <p>app.js</p>
  <pre><code>//app.js
  'use strict';
  var debug = require('debug');
  var express = require('express');
  var path = require('path');
  var favicon = require('serve-favicon');
  var logger = require('morgan');
  var cookieParser = require('cookie-parser');
  var bodyParser = require('body-parser');
  var session = require('express-session');
  var app = express();
  const { getSearchPage, search } = require('./routes/search');
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({ extended: true }));
         
  app.set('port', process.env.PORT || 3000);
  var server = app.listen(app.get('port'), function () {
    debug('Express server listening on port ' + server.address().port);
          });
   
  app.get('/search', getSearchPage);
  app.post('/search', search);        
          
  // view engine setup
  app.set('views', path.join(__dirname, 'views'));
  app.set('view engine', 'ejs'); 
        
  app.use(logger('dev'));
  app.use(cookieParser());
  app.use(express.static(path.join(__dirname, 'public')));
  </code></pre>
  <p>search.js</p>
  <pre><code>//search.js (in routes folder)
  module.exports = {
    getSearchPage: (req, res) =&gt; {
      res.render('search.ejs');
    },
    search: (req, res) =&gt; {
      var artist = req.body.searchArtist;
      var song = req.body.searchSong;
      var genre = req.body.searchGenre;
      var decade = req.body.searchDecade;
      console.log(&quot;The variables from the page: &quot;, req.body, artist, song, genre, decade); //logs &quot;{} undefined undefined undefined undefined&quot;
      if (song) {
        //query the database and return some results
      }
      res.render('search.ejs', { outputArray: outputArray });
    }
  }
  </code></pre>
  <p>search.ejs</p>
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang=&quot;en&quot; and dir=&quot;Itr&quot;&gt;
  
  &lt;head&gt;
      &lt;meta charset=&quot;utf-8&quot;&gt;
      &lt;title&gt;Home&lt;/title&gt;
      &lt;!--link rel=&quot;stylesheet&quot; href=&quot;css/search.css&quot;--&gt;
      &lt;script src=&quot;https://kit.fontawesome.com/9b28d88510.js&quot; crossorigin=&quot;anonymous&quot;&gt;&lt;/script&gt;
  
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;form method=&quot;post&quot; enctype=&quot;multipart/form-data&quot;&gt; 
    &lt;div class=&quot;search-box&quot;&gt;
        &lt;input class=&quot;search-txt&quot; type=&quot;text&quot; name=&quot;searchSong&quot; placeholder=&quot;Type to search&quot;&gt;
        &lt;a class=&quot;search-btn&quot; href=&quot;#&quot;&gt;
          &lt;i class=&quot;fas fa-search&quot;&gt;&lt;/i&gt;
        &lt;/a&gt;
    &lt;/div&gt;  
  
    &lt;div class=&quot;search-box2&quot;&gt;
      &lt;input class=&quot;search-txt2&quot; type=&quot;text&quot; name=&quot;searchArtist&quot; placeholder=&quot;Type to search&quot;&gt;
      &lt;a class=&quot;search-btn2&quot; href=&quot;#&quot;&gt;
        &lt;i class=&quot;fas fa-search&quot;&gt;&lt;/i&gt;
      &lt;/a&gt;
  &lt;/div&gt;  
  
  &lt;div class=&quot;search-box3&quot;&gt;
      &lt;input class=&quot;search-txt3&quot; type=&quot;text&quot; name=&quot;searchGenre&quot; placeholder=&quot;Type to search&quot;&gt;
      &lt;a class=&quot;search-btn3&quot; href=&quot;#&quot;&gt;
        &lt;i class=&quot;fas fa-search&quot;&gt;&lt;/i&gt;
      &lt;/a&gt;
  &lt;/div&gt;  
  
  &lt;div class=&quot;search-box4&quot;&gt;
      &lt;input class=&quot;search-txt4&quot; type=&quot;text&quot; name=&quot;searchDecade&quot; placeholder=&quot;Type to search&quot;&gt;
      &lt;a class=&quot;search-btn4&quot; href=&quot;#&quot;&gt;
        &lt;i class=&quot;fas fa-search&quot;&gt;&lt;/i&gt;
      &lt;/a&gt;
  &lt;/div&gt; 
  &lt;button type=&quot;submit&quot;&gt;Search!&lt;/button&gt;
  &lt;/form&gt;
  
  &lt;% if(typeof outputArray != 'undefined'){%&gt;
   &lt;ul&gt;
      &lt;% outputArray.forEach(function(song) { %&gt;
          &lt;li&gt;&lt;%= song %&gt;&lt;/li&gt;
      &lt;% }); %&gt;
  &lt;% } %&gt;
    &lt;/ul&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>I've tried setting urlencoded({extended: }) to true and to false, I've tried changing the form type to application/x-www-form-urlencoded, I've tried changing the post to a get, I've made sure I have body-parser installed, I've tried putting the routes before the server declaration. I've read through most of the pages here on the same issue, but none of those fixes have worked for me. Even more confusingly, I'm following almost exactly with <a href="https://dev.to/achowba/build-a-simple-app-using-node-js-and-mysql-19me" rel="nofollow noreferrer">this tutorial</a>, and I don't think I've missed anything that they did. This is my first time ever using Node.js/Express.js/EJS, but I've read through countless forum posts on this exact topic and I still can't figure out where it's going wrong.</p>