title: Node.js - Redirecting in Express with a Master / Detail Page
body: <p>I am learning Node.js. I am in the process of building a basic app for the sake of learning. At this time, I'm trying to do a master/detail page. Here is the master page.</p>
  
  <p><strong>/views/master.ejs</strong></p>
  
  <pre><code>&lt;html&gt;
    &lt;body&gt;
      [items would go here]
      &lt;a href="/new"&gt;add new&lt;/a&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The user will see this page when they visit '/'. When they click the "add new" link, I will take them to "/new". The code for the view is here:</p>
  
  <p><strong>/views/detail.ejs</strong></p>
  
  <pre><code>&lt;html&gt;
    &lt;body&gt;
      &lt;form id="myForm" method="post" action="/new"&gt;
        &lt;button type="submit"&gt;Submit&lt;/button&gt;
      &lt;/form&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I have these successfully working. However, when a user clicks submit, I'm not sure how to redirect them back to the "/" view. At this time, my routing code looks like this:</p>
  
  <pre><code>var router = require('express').Router();
  
  /* GET the master page. */
  router.get('/', function(req, res) {
      res.render('master', { });
  });
  
  /* GET the new page */
  router.get('/new', function(req, res) {
      res.render('detail', { });
  });
  
  /* POST new item */
  router.post('/new', function(req, res) {
      console.log('creating item...');
  
      // The following line just shows "undefined" in the browser"
      // I don't know if 1) Its correct or 2) If I should do it some other way
      res.redirect(200, '/', { }); 
  });
  </code></pre>
  
  <p>How do I handle loading views in a master-detail page scenario?</p>
  
  <p>Thanks!</p>