I tried to run my app on localhost using nodejs but i keep on getting this error : Uncaught SyntaxError: Unexpected token '<' .
This is my app.js code:
const http = require('http')
const fs = require('fs')
const port = 3000
const server = http.createServer(function(req,res){
res.writeHead(200,{'Content-Type':'text/html'})
fs.readFile('templates/index.html',null,function(error,data){
if(error){
res.writeHead(404)
res.write('Error: File Not Found')
} else {
res.write(data)
}
res.end()
})
})
server.listen(port,function(error){
if(error){
console.log('something went wrong', error)
}else{
console.log('server is listening on port ' + port)
}
})
I tried looking into other threads that discussed this but I'm pretty new to this and I have no clue what they are talking about just following YouTube tutorials at the moment.