separate file for routes in express : <p>I was wondering how do I move all of my api routes in express into a separate <code>routes.js</code> file from my <code>server.js</code> file</p>

<p>I have a long list of api routes using <code>app.use()</code> for each route. So each route is in its own file, e.g. <code>movies.js</code>, <code>movie.js</code> but when I list these it makes for a long list in <code>server.js</code></p>

<p>So I want to remove the list of api endpoints section from the below <code>server.js</code> out to a <code>routes.js</code> file. </p>

<p>Here is what I have currently:</p>

<p><strong>server.js</strong></p>

<pre><code>import path from 'path'
import express from 'express'
import webpack from 'webpack'
import webpackDevMiddleware from 'webpack-dev-middleware'
import webpackConfig from './webpack.config.dev'

const app = express();

/* api endpoints, can be many more, I want them in routes.js */    
app.use('/api/movies', require('./src/api/routes/movies'))
app.use('/api/movie', require('./src/api/routes/movie'))

app.use(webpackDevMiddleware(webpack(webpackConfig), {
  publicPath: webpackConfig.output.publicPath
}));

app.use('/public', express.static(__dirname + '/public'))    

app.get('*', function(req, res) {
  res.sendFile(path.join(__dirname, 'index.html'));
});


app.listen(3000, 'localhost', function (err) {
  if (err) {
    console.log(err);
    return;
  }
})
</code></pre>

<p>An example route </p>

<p><strong>movies.js</strong></p>

<pre><code>var express = require('express');
var request = require("request");
var router = express.Router();

router.get('/', function(req, res) {
  res.json({})
});

module.exports = router;
</code></pre>
