NodeJS - Multiple Router files
<p>I have 2 router files. One is for view routing and other for api requests.</p>

<p>I am trying to set the routing using:</p>

<pre><code>var routes = require('./routes/index'); //View Router
var api = require('./routes/api'); //API Router

app.use('/', routes);
app.use('/api', api);
</code></pre>

<p>This fails in case of /api requests. If I remove one of the routings, the other works.</p>

<p>I also tried,</p>

<pre><code>routes(app);
api(app);
</code></pre>

<p>But this fails too. Any idea what might be the issue? Please let me know in case additional details are required.</p>

<p>routers/index.js</p>

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

var Promise = require('bluebird');
var nforce = require('nforce');
var org = require('../lib/connection');

/* GET home page. */
router.get('/', function(req, res, next) {
    res.render('index', { title: 'App' });
});

router.get('/accounts', function(req, res, next){
console.log(org);
    res.render('partials/' + name);
    org.query({query: 'Select Id, Name, Type, Industry, Rating From Account Order By LastModifiedDate DESC'})
        .then(function(results){
            console.log(results);
            res.render('accounts', {title: 'Accounts', records: results.records});
        });
});

router.get('/partials/:name', function(req, res, next){
    var name = req.params.name;
console.log(name);
  res.render('partials/' + name);
});

router.get('/api/:name', function(req, res, next){
    var name = req.params.name;
console.log(name);
  res.render('api/' + name);
});
module.exports = router;
</code></pre>

<p>/routers/api.js</p>

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

var Promise = require('bluebird');
var nforce = require('nforce');
var org = require('../lib/connection');

/* GET home page. */
router.get('/getAccounts', function(req, res, next) {
    console.log('in API router...');
    org.query({query: 'Select Id, Name, Type, Industry, Rating From Account Order By LastModifiedDate DESC'})
    .then(function(results){
        console.log(results);
        res.json({'accounts': results.records});
    });
});
module.exports = router;
</code></pre>