Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

135
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda