What is the difference between
router.route('/create')
.post(validate(hotelValidation.createHotel), function (req, res) {
and simply
router.post('/create', validate(hotelValidation.createHotel), function (req, res) {
Are these the same? What does the route keyword accomplish here?
Are these the same? What does the route keyword accomplish here?
Here it accomplishes nothing. But you could do:
app.route('/some/very/long/path/that/you/dont/want/to/duplicate/risking/errors')
.get(function (req, res) {
})
.post(function (req, res) {
})
.put(function (req, res) {
});
Instead of:
router.get('/some/very/long/path/that/you/dont/want/to/duplicate/risking/errors', function (req, res) {
})
router.post('/some/very/long/path/that/you/dont/want/to/dpulicate/risking/errors', function (req, res) {
})
router.put('/some/very/long/path/that/you/dont/want/to/dulpicate/risking/errors', function (req, res) {
});
router.route(path) creates an instance of a single Route for the given path.
Using router.route(path) is a recommended approach to avoiding duplicate route naming and thus typo errors.
router.[method] like "post" and "get" These are functions which you can directly call on a route to register a new handler for the method on the route.