title: Importing/exporting the Express router using ES6 import + export keywords and Babel
body: <p>I have an old test project originally built with Express 2.X. I am moving it to Express 4.x and trying to insert Babel 6.x to experiment with ES6 features server-side.</p>
  
  <p>The update to Express 4.x went OK. The original app works fine. The problems arise when I start adding ES6 features.</p>
  
  <p>In particular, I want to substitute all <code>require</code> and <code>module.export</code> instructions with ES6 <code>import {...} from...</code> and <code>export {...}</code>.</p>
  
  <p>Problem: I seem unable to import routes from external files into the main <code>app.js</code> file.</p>
  
  <p>My <code>app.js</code> loads routes like so:</p>
  
  <pre><code>import { indexRoute } from './routes/index_route';
  app.use('/', indexRoute);
  </code></pre>
  
  <p>Inside <code>index_route.js</code> I have:</p>
  
  <pre><code>"use strict";
  import express from 'express';
  var router = express.Router();
  
  router.get('/', function(req, res, next) {
    res.render('index_view', { title: 'Express' });
  });
  
  export { router }
  </code></pre>
  
  <p>This source code is OK for Babel, but node complains at startup:</p>
  
  <pre><code>Router.use() requires middleware function but got a undefined
  </code></pre>
  
  <p>I have two files like <code>index_route.js</code>, each one for a group of routes, and AFAIS they both import + modify + export the same router object. In any case, the export+import done using ES6 keywords returns <code>undefined</code>.</p>
  
  <p>What am I doing wrong? Am I using the ES6 keywords on the wrong objects? Am I using obsolete instructions to configure the routes inside <code>app.js</code>?</p>