Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

134
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!