title: Unable to pass data through Express Middleware locals
body: <p>I am attempting to pass data from a middleware controller method to the view, however when attempting to access res.locals in my get method, it returns empty. When logging the array from the controller method, it is filled, but the array seems to clear when attempting to access it in the get request.</p>
  <p>the snippet below skips the logic of filling the array and uses arbitrary values for resArray. I would like to access res.locals in server.js</p>
  <p>controller.js</p>
  <pre><code>function createTable(req, res, next){
                  let resArray = [8, 9, 10];
                  req.resArray = resArray; //sending array to locals
                  console.log(req.resArray);
                  res.locals.resArray = resArray;
                  console.log(&quot;LOCALS FROM CONTROLLER: &quot;, res.locals); //Logs [8, 9, 10]
                  next();
  }
  </code></pre>
  <p>server.js</p>
  <pre><code>app.get('/', createTable, (req, res) =&gt; {
      console.log(&quot;LOCALS: &quot;, res.locals); //Logs empty object
      res.render(&quot;index&quot;);
      
  });
  </code></pre>
  <p>body from index.ejs</p>
  <pre><code>&lt;form action=&quot;./&quot; method=&quot;get&quot; id=&quot;form&quot;&gt;
      &lt;!-- endpoint of API to be selected --&gt;
      &lt;select name=&quot;endpoint&quot;&gt;
          &lt;option value=&quot;albums&quot;&gt;Albums&lt;/option&gt;&gt;
          &lt;option value=&quot;posts&quot;&gt;Posts&lt;/option&gt;
          &lt;option value=&quot;todos&quot;&gt;Todos&lt;/option&gt;
      &lt;/select&gt;
      &lt;select name=&quot;order&quot;&gt;
          &lt;option value=&quot;first&quot;&gt;First&lt;/option&gt;
          &lt;option value=&quot;last&quot;&gt;Last&lt;/option&gt;
      &lt;/select&gt;
          Count: &lt;input type=&quot;number&quot; name=&quot;count&quot; placeholder=&quot;1&quot; /&gt; &lt;br&gt;
          UserId: &lt;select name=&quot;userIdSelected&quot;&gt;
                      &lt;option value=&quot;1&quot;&gt;1&lt;/option&gt;
                      &lt;option value=&quot;2&quot;&gt;2&lt;/option&gt;
                      &lt;option value=&quot;3&quot;&gt;3&lt;/option&gt;
                      &lt;option value=&quot;4&quot;&gt;4&lt;/option&gt;
                      &lt;option value=&quot;5&quot;&gt;5&lt;/option&gt;
                      &lt;option value=&quot;6&quot;&gt;6&lt;/option&gt;
                      &lt;option value=&quot;7&quot;&gt;7&lt;/option&gt;
                      &lt;option value=&quot;8&quot;&gt;8&lt;/option&gt;
                      &lt;option value=&quot;9&quot;&gt;9&lt;/option&gt;
                      &lt;option value=&quot;10&quot;&gt;10&lt;/option&gt;
              &lt;/select&gt;
      &lt;input type=&quot;submit&quot;&gt;
  &lt;/form&gt;
  </code></pre>