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

165
Views
Express, make all routes begin with /api

Is there any way to make all the routes that express accepts start with /api without having to define it explicitly?

Current:

this.app.get('/api/endpoint-A', (req, res) => {
   return res.send('A');
});
this.app.get('/api/endpoint-B', (req, res) => {
   return res.send('B');
});

Objetive:

this.app.get('/endpoint-A', (req, res) => {//https:host.com/api/endpoint-A
   return res.send('A');
});
this.app.get('/endpoint-B', (req, res) => {//https:host.com/api/endpoint-B
   return res.send('B');
});
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Add

app.use('/api/:version/', router);

after you have created a base express router.

about 4 years ago · Juan Pablo Isaza 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!