Get information from a url using node + express + ejs

1

I have created a url in the following format: localhost:8080/forgetPassword/id/hash

I have this route rendering:

app.get('/forgetPassword', function(req, res) {
    res.render('pages/forgetPassword');
});

So I would like to target the url localhost:8080/forgetPassord and get the rest of url id/hash where I will do the validation. However, I can not find a way to get this data.

    
asked by anonymous 11.08.2016 / 18:29

1 answer

2

You can use params , which pass properties to req these values. The syntax is:

  

/:nomeDaVariavel that is: / + : + nome da variável

Test like this:

app.get('/forgetPassword',(req, res) => {
    res.render('pages/forgetPassword');
});

app.get('/forgetPassword/:id/:hash', (req, res) => {
    const id = req.params.id;
    const hash = req.params.hash;

    // fazer algo com "id" e "hash" e depois o redirect:
    res.redirect('/forgetPassword');
});
    
11.08.2016 / 18:38