title: Redirect after already used response Node js
body: <p>I want to render some page and after certain amount of seconds it needs to be redirected to another page. However, I get an "Can't set headers after they are sent." From what I read, the response should be used only once, though I'm not sure if this is true.  I would appreciate any help or solution to this particular problem.</p>
  
  <pre><code>app.get('/', function (req, res) {
      var message = req.flash();
      res.render('index', { message: req.flash('message'), hassError: message.length &gt; 0} );
  });
  
  app.get('/error', function (req, res) {
      var timeout = 3000;
  
      setTimeout(function (err) {
          console.log('finished');
          if (err)
              throw err;
          console.log('################');
          res.redirect('/');
      }, timeout);
      res.render('partials/404');
  });
  </code></pre>
  
  <p>"finished" gets printed and then it throws error, but not the err specified in callback.</p>