Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

143
Vistas
Difference between adding route keyword in defining route in Express

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?

about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

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) {
  });
about 4 years ago · Santiago Trujillo Denunciar

0

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.

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda