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

93
Views
Run middleware when a specific placeholder is set (express.js)

I have a REST API and many endpoints include a specific placeholder, like this:

app.get('/client/:client', getClient);
app.put('/client/:client', updateClient);
app.get('/tasks/:client', getClientTasks);
// ...

I want to run a middleware for all paths, that include the :client placeholder.

This is what I've come up with, but it does not work for me:

// My sample middleware:
function validateClient(req, res, next) {
    console.log('Validate client', req.params.client);
    next();
}

// I want to bind the middleware to all endpoints with ':client' in them:
app.use(':client', validateClient);       // <- validateClient is not called!?

// The REST endpoints.
app.get('/client/:client', getClient);
app.put('/client/:client', updateClient);
app.get('/tasks/:client', getClientTasks);
about 4 years ago · Juan Pablo Isaza
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!