scotch-io/node-api

A little question

Closed this issue · 2 comments

When I have lots of routes to config, how to manage these routes in a anther file(files)?
And What I should include the routes file in the server.js?

I'm a rookie.

Thank you.

There are a few different ways you can do this. As long as you have each routes file with module.exports inside of it, you can call that file from any other file.

So you could have multiple routes files like /routes/app.js, /routes/dashboard.js, /routes/api.js.

Then you could call all those inside of server.js separately:

var appRoutes = require('./routes/app.js');
var dashboardRoutes = require('./routes/dashboard.js');
var apiRoutes = require('./routes/api.js');

app.use('/app', appRoutes);
app.use('/dashboard', dashboardRoutes);
app.use('/api', apiRoutes);

Thank you very much!