Hi! I wanted to make my small API server on NODE.js, but I ran into the problem that the server does not see the id variable from the query string and I constantly get code from else{...} .

 router.get('/:id',(req,res,next)=>{ const id = req.param.id; if (id === 'special') { res.status(200).json({ message: 'You discover the special Id', id : id }); }else{ res.status(200).json({ message: '', id: id }); } } ); 

Can you tell me how to fix this?

  • And what does he see instead of a variable? - Dmytryk
  • Nothing! I get the answer {message : ''} . - Oleksandr Tatarinov

2 answers 2

Hey. You have a typo in the code:

  const id = req.param.id; 

It should be:

  const id = req.params.id; 

The req.param block does not exist.

Rating is not in the comment write)

  • Thank you! I already thought express beaten downloaded :) - Oleksandr Tatarinov

You have a typo when getting the ID (second line, there must be a paramS). try

 const id = req.params.id;