title: Express.js res.render() and res.redirect()
body: <p>I have a route in my express app, which is supposed to do the following:</p>
  
  <ul>
  <li>Get some data from outside (OK)</li>
  <li>Show a HTML page with socket.io listening for messages (OK)</li>
  <li>Perform some calculations, which take a long time</li>
  <li>Send a message trough socket.io after each one one completed (OK)</li>
  <li>When all calculations are completed, show a result page (problem)</li>
  </ul>
  
  <p>So, a simplified version of my code is:</p>
  
  <pre><code>module.exports = function(io) { // This is so I can use socket.io inside the route
    var express = require('express');
    var router = express.Router();
  
    [... and other required]
  
    router.post('/', function(req, res, next) {
      res.render('loading'); // This renders the template which holds accepts and renders socket.io messages
      pefromCalculaton();
      sendSocketIOMessage();
      session.data = resultData; // I get the result of all calculations and put that in the session. It's a quick fix, don't judge, I've got no presistancy in my project as for now...
      res.redirect('results'); // And here I'd like to go to the other route, which will display the data, getting it from the session.
    }); 
    return router;
  }
  </code></pre>
  
  <p>Since this doesn't work, I am probably trying to do something really stupid here. But what I actually want to do is:</p>
  
  <ul>
  <li>Perform calculations</li>
  <li>While performing the calculations, update progress using sockets</li>
  <li>When calculation is done, render a template, showing all the results.</li>
  </ul>