Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

251
Vistas
Why do I get Error: Cannot find module 'html' when running nodejs express server?

I'm trying to create a server for my HTML application, but when I go to localhost:8080/map I get Error: Cannot find module 'HTML'. Still, the main at localhost:8080 page works fine.

My code :

const path = require('path');
const port = 8080;
const express = require('express');
const app = express();

app.use(express.static(path.join(__dirname, 'public')));
app.set("view engine", html);


app.get('/', (req, res) => {
    res.render('index.html')
})

app.get('/map/', (req, res) => {
    res.render('map.html')
})

var server = app.listen(8080, function () {
    console.log(`App listening at http://localhost:${server.address().port}/`)
 })
about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

You are using EJS so you need to do this

app.set('view engine', 'html');

app.engine('html', require('ejs').renderFile);

Use the app.engine(ext, callback) method to create your own template engine. ext refers to the file extension, and callback is the template engine function, which accepts the following items as parameters: the location of the file, the options object, and the callback function.

So with that you actually make the node runtime to load the 'html' template engine and it works fine.

Please refer to this link

Also you are missing quotes on this line app.set("view engine", html);. It should be app.set("view engine", "html");

about 4 years ago · Santiago Trujillo Denunciar

0

const express = require('express');
const app = express();

app.use('/', express.static(__dirname + '/'));
app.get('/', function(req, res) {
    //res.render('index.html')
    //Such a static call assumes the existence of an index.html file at the call address:  nodejs\node_modules\index.html
  });

 app.get('/map', function(req, res) {
    res.send('Taylor Swift');
  });
app.listen(8080);
console.log(`App listening at http://localhost:8080/map`)

about 4 years ago · Santiago Trujillo Denunciar
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 Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda