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

111
Views
Should I check if route params exist inside a controller?

I'm working on an Express app, and one of the routes looks like this

router.put(
  '/countries/:countryId/regions/:regionId/cities/:cityId',
  runAsyncWrapper(updateCity),
);

Inside the controller I have these checks

const {
    params: { countryId, regionId, cityId },
    body,
  } = req;
   if (!countryId) throw new CountryIdRequired();
   if (!regionId) throw new RegionIdRequired();
   if (!cityId) throw new CityIdRequired();

Do those checks even make any sense? Since these IDs are used in the route string, is there any chance that this controller (which is used only with that one route) will be called, and some of the params will be null or undefined?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Express should answer with HTTP 404 if your params are not set.

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!