How to set default path (route prefix) in express?

Solution 1:

Using Express 4 you can use Router

var router = express.Router();
router.use('/user', user);

app.use('/api/v1', router);

Solution 2:

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')
  });