• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

196
Vistas
Uncaught SyntaxError: Unexpected token '<' error

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.

about 3 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda