How to set default path (route prefix) in express?
If you are using Express 4 Router
you can use route() method to set the path and create a chainable route handler
app.route('/book')
.get(function (req, res) {
res.send('Get a random book')
})
.post(function (req, res) {
res.send('Add a book')
})
.put(function (req, res) {
res.send('Update the book')
});
Using Express 4 you can use Router
var router = express.Router();
router.use('/user', user);
app.use('/api/v1', router);