When you use Express you have the freedom to send Text or JSON data back to the frontend easily.
Sending JSON Data
You can send JSON data with the res.json method.
app.get('/data', (req, res) => { res.json({ message: 'JSON data', })})Once you have this route, you will be able to receive the JSON data from the server.
zlFetch('http://localhost:3000/json') .then(response => { console.log(response.body) })
Sending Text Data
You can send JSON data with the res.text method.
app.get('/text', (req, res) => { res.text('Text data')})Once you have this route, you will be able to receive text data from the server.
zlFetch('http://localhost:3000/text') .then(response => { console.log(response.body) })
That’s all you need to know for this lesson.
Welcome! Unfortunately, you don’t have access to this lesson. To get access, please purchase the course or enroll in Magical Dev School.
Unlock this lesson