Closed
Description
Currently, routes.js exports a function that receives an app parameter, then it adds all the routes on this express app.
Express 4 now exports the router api, that way, you can do something like this:
In routes.js:
var api = express.Router();
api.route('/users')
.post(users.create)
.put(users.changePassword);
module.exports = api;
Why? Because then in server.js you can do:
app.use('/api', require('./lib/routes'))
This will respond to:
/api/users
Then say you want to upgrade your api. So you add v2.0. All you do is take that little line of code and change it to:
app.use('/api/v1', require('./lib/routes'))
And that's it. All your routes are now prefixed that way. It's more reusable. You can easily group your apis and then move them around as you see fit.
Metadata
Metadata
Assignees
Labels
No labels