cleopatez
cleopatez

Reputation: 237

Getting ID of current user into the URL of a method in NodeJS

What I want to do is having the ID of the current user into the url parameter for my Express patch method. Is it even possible to do this? I could get the ID from the Axios request but it cannot be passed without using a method. Hope anyone could enlighten me on this issue.

app.patch(`/users/edit/{id-of-the-user}`, (req, res) => {
  console.log(req.body);
});

Upvotes: 1

Views: 975

Answers (1)

wangdev87
wangdev87

Reputation: 8751

Use req.params. Refer to Express Routing.

app.patch(`/users/edit/:userId`, (req, res) => {
  console.log(req.params.userId);
});

Upvotes: 2

Related Questions