I have a fetch request and it works fine. My question is when I try to log a specific response I get undefined but when I log the whole response I get the string printed correctly. How can I call and log a specific var from the back end. I tried console.log(respone.line)
but as I said it logs undefined
.
//Backend
function getInfo() {
const line = "this is test"
return line
}
async function callGetInfo() {
const data1 = await getInfo()
return data1
}
module.exports = {
callGetInfo
};
//Frontend
function fetcher() {
fetch(`http://localhost:PORT/api/routePath`)
.then((res) => {
return new Promise((resolve, reject) => {
resolve(res.json())
})
}).then((response) => {
//displays the response
console.log(response)
//displays undefined
console.log(response.line)
}
}
fetcher()