Basic Node and Express - Get Route Parameter Input from the Client

Basic Node and Express - Get Route Parameter Input from the Client
0.0 0

#1

Hi while trying to solve this i see that it can be done by two ways… please could someone tell me if there is a particular way to follow or are both acceptable methods as long as its passing the tests.
thank you.

1st method:

app.get(’/:echo/echo’, function(req, res) {
res.json(req.params);
});

2nd method:

app.get(’/:word/echo’, function(req, res) {
res.json({‘echo’: req.params.word});
});

PS. please let me know if there is a correct way to go around or if it doesnt matter at this point


#2

As long as you get what the challenge wants you to do, that’s great. there is no particular way to “pass” the challenge. the methods do the same thing, so you can use either one.:full_moon_with_face:


#3

Though only 2nd Method is passing the test but as both are giving same solution so both of them are correct. 1st Method is more explicit and easy to read and work when multiple parameters are there