Closed hectorzaragoza closed 2 years ago
I am doing an API call in my router and passing along the api response via an object to access it in the ejs file I am res.rendering.
But, I can't access the object in the ejs file...it says it is undefined.
The route looks like this: (js) router.get('/main', (req, res) => { axios.get(`${baseUrl}+${testAddress}+${myKey}`) .then(apiResponse => { // let dataResponse = apiResponse.data.features res.render('main', {apiResponse}) console.log(apiResponse) // console.log(dataResponse) }) .catch(error => { console.log(error) }) }) (js)
js) router.get('/main', (req, res) => { axios.get(`${baseUrl}+${testAddress}+${myKey}`) .then(apiResponse => { // let dataResponse = apiResponse.data.features res.render('main', {apiResponse}) console.log(apiResponse) // console.log(dataResponse) }) .catch(error => { console.log(error) }) }) (
The main ejs file looks like this: (```js)
<%= apiResponse %>
(```js)
I have tried console logging the api response in both the route and the view but can't seem to figure out why it's not showing up in either place.
I am doing an API call in my router and passing along the api response via an object to access it in the ejs file I am res.rendering.
But, I can't access the object in the ejs file...it says it is undefined.
The route looks like this: (
js) router.get('/main', (req, res) => { axios.get(`${baseUrl}+${testAddress}+${myKey}`) .then(apiResponse => { // let dataResponse = apiResponse.data.features res.render('main', {apiResponse}) console.log(apiResponse) // console.log(dataResponse) }) .catch(error => { console.log(error) }) }) (
js)The main ejs file looks like this: (```js)
<%= apiResponse %>
(```js)
I have tried console logging the api response in both the route and the view but can't seem to figure out why it's not showing up in either place.