nested routes in expressJS
<p>I have the following routes defined</p>

<pre><code>router.get('/:company', function (req, res, next) {
    // 1. call database and get company data
    // 2. render company view
})

router.get('/:company/employees', function (req, res, next) {
    // 1. call database and get company data
    // 2. call database and get employees data
    // 3. render employees view
})
</code></pre>

<p>How can I merge these 2 routes to make only one call to the database to get company data. Basically I just want to reuse that logic.</p>

<p>I´m looking for something like this (tested but it doesn't work)</p>

<pre><code>router.get('/:company', function (req, res, next) {
    // 1. call database and get company data
    // 2. render company view

    router.get('/:company/employees', function (req, res, next) {
        // no need to call database to get company data. we already have it
        // 1. call database and get employees data
        // 2. render employees view
    })

})
</code></pre>