Node-Express: how to take query and redirect

Hello, Maybe someone could help. As in the title, how to get query params ans use them to redirect to the proper page? The output is [object Object]

let {query} = req;
res.send(`${query}`)

Hi @GM_sql

You need to be a little more elaborate in what you are trying to achieve. You are correctly accessing the query parameters. You should be aware that query is an object. Assuming you hit the following endpoint

/api/v1/country?iso2=ca&region=americas

The query object will look like:

{
    iso2: 'ca',
    region: 'americas'
}

You can redirect to another site using the following.

res.redirect('https://www.forum.freecodecamp.org');

I hope that helps.

The problem is already solved. What I wanted to do was to redirect, as an example, to :

res.redirect('https://www.forum.freecodecamp.org?iso2=ca&region=americas');

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.