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

187
Views
Getting input from URL using node.js

I was given the following task:

define the route

GET /api/restaurants

This route must accept the numeric query parameters "page" and "perPage" as well as the string parameter "borough", ie: /api/restaurants?page=1&perPage=5&borough=Bronx. It will use these values to return all "Restaurant" objects for a specific "page" to the client as well as optionally filtering by "borough", if provided.

my code is as follows

app.get('/api/restaurants/:page/:perPage/:borough', (req, res) =>{
  console.log("worked")
  console.log(req.params.page)
  console.log(req.params.perPage)
  console.log(req.params.borough) 
})

now here is the issue i m encountering, the route works fine if i enter the url in the following format

http://localhost:8000/api/restaurants/1/5/Bronx

however it doesn't work when using the format the instructor requires

http://localhost:8000/api/restaurants?page=1&perPage=5&borough=Bronx

I get "Cannot GET /api/restaurants", if anyone could please shed some light on what i m doing wrong i would appreciate it.

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

0

I think you're confusing route parameters and query parameters. (They are not the same.)

You can access query parameters on req.query:

app.get('/api/restaurants', (req, res) => {
  console.log(req.query.page);
  console.log(req.query.perPage);
  console.log(req.query.borough);
});
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!