user5062472
user5062472

Reputation:

Catching parameters in query string at NodeJs simple mock

I'm working on a simple mock server, and am using nothing but JavaScript and Yarn to build it.

In a simplistic manner, I have this that's working as intended:

function server() {
(...)

return {
    users: generate(userGenerator, 150)
}

This is generating 150 random users, when the /users endpoint is reached, and it's working as intended. The issue I'm having is with catching id's passed on the query string. ie:

/users/{id}/attribute

How can I get this to work?

Many thanks in advance

Upvotes: 0

Views: 747

Answers (1)

Adesh Shah
Adesh Shah

Reputation: 442

try req.params.id

app.get('/users/:id/attribute', function(req, res) {
    console.log('id : ' + req.params.id);
    ...
});

Upvotes: 1

Related Questions