title: Filter search get an error message of req is not defined
body: <p>I have created a multiple drop down menu so users can filter search by city, bedrooms, and bathrooms. The form will return all data that apply to the user's search. The search function, bedroomSearch function, and bathroomSearch function will handle all the search filtering. For some odd reason I keeping getting an error message saying  "ReferenceError: req is not defined". How do I get my filter to work?</p>
  
  <p>form.ejs</p>
  
  <pre><code>&lt;form action="/homes" method="GET" class="filter-form"&gt;
  
      &lt;select name="search" id="form-city"&gt;
      &lt;option value="" disabled selected&gt;Search by City&lt;/option&gt;
        &lt;option value="New York"&gt;New York&lt;/option&gt;
    &lt;option value="CA"&gt;California&lt;/option&gt;
    &lt;option value="MI"&gt;Michigan&lt;/option&gt;
    &lt;option value="Hawaii"&gt;Hawaii&lt;/option&gt;
  &lt;/select&gt;
  
  &lt;select name="bed"&gt;
      &lt;option value="3 Beds"&gt;3 Beds&lt;/option&gt;
    &lt;option value="5 Beds"&gt;5 Beds&lt;/option&gt;
    &lt;option value="6 Beds"&gt;6 Beds&lt;/option&gt;
    &lt;option value="8 Beds"&gt;8 Beds&lt;/option&gt;
  
  &lt;/select&gt;
  
  &lt;select name="bath"&gt;
      &lt;option value="" disabled selected&gt;Bathrooms&lt;/option&gt;
        &lt;option value="New York"&gt;New York&lt;/option&gt;
    &lt;option value=" 3.5 baths"&gt; 3.5 baths&lt;/option&gt;
    &lt;option value="5 baths"&gt; 5 baths&lt;/option&gt;
    &lt;option value="6 baths"&gt; 6 baths&lt;/option&gt;
  &lt;/select&gt;
  
  
                &lt;input type="submit" value="SEARCH" class="site-btn fs-submit"&gt;
            &lt;/form&gt;
  
  
  </code></pre>
  
  <p>house.js</p>
  
  <pre><code>router.get("/", function(req, res){
    //function to search by city
    search();
  
    //function to search by bedrooms
    bedroomSearch();
  
    //function to search by bathrooms
    bathroomSearch()
  });
  
  //search functions
  function citySearch() {
    var noMatch = null;
      if(req.query.search) {
          const regex = new RegExp(escapeRegex(req.query.search), 'gi');
          // Get all homes from DB
          Home.find({city: regex}, function(err, allHomes){
             if(err){
                 console.log(err);
             } else {
                if(allHomes.length &lt; 1) {
                    noMatch = "No homes match that query, please try again.";
                }
                res.render("homes/index",{homes:allHomes, noMatch: noMatch});
             }
          });
      } else {
          // Get all homes from DB
          Home.find({}, function(err, allHomes){
             if(err){
                 console.log(err);
             } else {
                res.render("homes/index",{homes:allHomes, noMatch: noMatch});
             }
          });
      }
  
  }
  // end of city search function
  
  function bedroomSearch() {
    var noMatch = null;
      if(req.query.bed) {
          const regexBed = new RegExp(escapeRegex(req.query.bed), 'gi');
          // Get all homes from DB
          Home.find({bedrooms: regexBed}, function(err, allHomes){
             if(err){
                 console.log(err);
             } else {
                if(allHomes.length &lt; 1) {
                    noMatch = "No homes match that query, please try again.";
                }
                res.render("homes/index",{homes:allHomes, noMatch: noMatch});
             }
          });
      } else {
          // Get all homes from DB
          Home.find({}, function(err, allHomes){
             if(err){
                 console.log(err);
             } else {
                res.render("homes/index",{homes:allHomes, noMatch: noMatch});
             }
          });
      }
  
  }
  
  //end of bed function
  
  function bathroomSearch() {
    var noMatch = null;
      if(req.query.bath) {
          const regexBath = new RegExp(escapeRegex(req.query.bath), 'gi');
          // Get all homes from DB
          Home.find({bathrooms: regexBath}, function(err, allHomes){
             if(err){
                 console.log(err);
             } else {
                if(allHomes.length &lt; 1) {
                    noMatch = "No homes match that query, please try again.";
                }
                res.render("homes/index",{homes:allHomes, noMatch: noMatch});
             }
          });
      } else {
          // Get all homes from DB
          Home.find({}, function(err, allHomes){
             if(err){
                 console.log(err);
             } else {
                res.render("homes/index",{homes:allHomes, noMatch: noMatch});
             }
          });
      }
  
  }
  
  //end of bathroom function
  
  
  // For form 
  function escapeRegex(text) {
      return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&amp;");
  };
  
  </code></pre>