title: Node.JS: Create new pages with Express
body: <p>I am trying to find a way to create a new page dynamically on Node.JS with Express when a user submits a form. Here is my idea, but it doesn't work:</p>
  
  <pre><code>var app = require('express')();
  var server= require('http').createServer(app);
  var bodyParser = require('body-parser'); 
  var urlencodedParser = bodyParser.urlencoded({ extended: false });
  
  function Page(name){ //Create a page prototype
  //Some variables and methods specific to the page
            app.get('/'+name, function (req, res) {
                 res.render('index.ejs', {someVars: someVars});
            });
   }
  
  //When a user submits a form, create a new page
  app.post('/submit', urlencodedParser, function(req, res){   
      var nom = req.body.nom;
      var newPage = new Page(nom);
      res.redirect('http://myDomain/' + nom);
  });
  </code></pre>
  
  <p>What is the best way to do it?</p>