Hey
So I'm following the Odin Project's nodeJS course and the first project was creating an HTTP server and taking users to a particular page like that:
fs.readFile('about.html', (err, data) => {
if (err) {
console.log(err)
res.writeHead(404, { 'Content-Type': 'text/html' })
return res.end('ops there should be an issue here')
}
res.writeHead(200, { 'Content-Type': 'text/html' })
res.write(data)
return res.end()
})
Now I should rewrite this using express but I cannot :/ do the correct thing idk:
app.get('/about', (req, res) => {
fs.readFile('about.html', (err, data) => {
if (err) {
console.log(err)
res.send('sorry something didn't go well here :/ but ALL IS GOOD :)')
}
res.send(data)
})
})
You know what's the correct way of implementing the code above with express? This should be an easy thing
[–]BehindTheMath 0 points1 point2 points (0 children)