A month after the fact, I am going to answer it differently. You just wanted it to work, and you have a solution for it to work. But what if you really want the other routes.js handle more of your routes? Fear not a node can handle it!
Assuming this structure,
- app.js - routes/ - index.js - foo.js
And let's say you need the syntax in app.js
app.get('/test', routes.foo.test);
To do this in routes.js add,
var foo = exports.foo = require('./foo');
Then in app.js you will have,
var routes = require('./routes');
This will work, it will let you say in app.js ,
app.get('/test', routes.foo.test);
This will give you one more level to organize your routes. I usually like to keep all my routes organized under the routes object, but if you want to import directly into main, you can too,
var foo = require('./routes/foo'); app.get('/test', foo.test);
source share