title: Best way to do dynamic routing with Express.js (node.js)
body: <p>I'm trying to create a simple CMS with express.js that dynamically creates routes.
  It gets a JSON from a database that looks like this:</p>
  
  <pre><code>pagesfromdb = {
      home = {
          paths = ['/','/home','/koti'],
          render = 'home.ejs',
          fi_FI = {html='&lt;h1&gt;Hei maailma!&lt;/h1&gt;'},
          en_US = {html='&lt;h1&gt;Hello World!&lt;/h1&gt;'}
      },
      about = {
          paths = ['/about','/tietoja'],
          render = 'general.ejs',
          fi_FI = {html='Tietoja'},
          en_US = {html='About Us'}
      }
  }
  </code></pre>
  
  <p>and iterates over the objects creating routes like so:</p>
  
  <pre><code>Object.keys(pagesfromdb).forEach(function(key) {
      var page = pagesfromdb[key];
      app.get(page.global.paths,function(req, res){
           res.render(page.render, page[language]);
      });
  });
  </code></pre>
  
  <p>Now everything is working fine. But the problem is, every time a user modifies the content and paths, the whole node app needs to be restarted.
  I didin't find any API calls to remove routes.</p>
  
  <p>Is there any way to safely remove the old routes set with app.get? Should I even do that?</p>
  
  <p>Is there a better way to do this kind of routing? I do like this method as it allows me to use the built in function, is fast and supports regex.</p>
  
  <p>I tried removing the whole app.routes with app.routes = nul but it didn't do anything, the old routes were still in place.</p>
  
  <p>One thing that did indeed remove them was </p>
  
  <pre><code>delete app._router.map.get;
  app._router.map.get = [];
  </code></pre>
  
  <p>But does this actually remove them and is it safe to use so I don't end up hijacking huge amounts of ram if the router keeps getting repopulated?</p>