I'm attempting to return a dynamically generated string back to the client from an Express post route.
Within the backend, I've set up a post route:
router.post('/', async (req, res) => {
try {
// Here, I perform computations on a succession that results in a new string each time
const foo = 'string that changes and needs to be sent to the client'
} catch (error) {
res.status(500).send(error)
}
})
On the client side, I'm using axios to send data via a post request:
(async () => {
try {
await axios.post('/api/send/', { data })
} catch (error) {
console.log(error)
}
})()
Is there a way for me to receive data back from the route after sending the post request?
I attempted to use res.send()
within the post route, but it caused functions on the backend to fail.
Thank you in advance.