Ask coding questions

← Back to all posts
req.param
Ryanstar301 (0)

I have used req.param but it keeps saying i need to use req.body, req.params or req.query and those both now work. I have tried things but nothing works, can someone help me?

Answered by Coder100 (18176) [earned 5 cycles]
View Answer
Comments
hotnewtop
Coder100 (18176)

You need to set them in ur path, like this:

app.get("/joinlogging/:userid/:name/:gameName", (req, res) => {
  var ID = req.params.userid;
  var Name = req.params.name;
  // ...
});

Express needs to know what goes where!

notGilbert (121)

It seems like there are no params in your handlers. Also, req.params is not a callable function, but an object.

needs to be in the format of:

app.get('/route/:id', (req, res) => {
  const id = req.params.id; // or req.params['id'];
  res.send(`ID: ${id}`);
});

you need to add a :paramName to your route and change () to [] or use .