Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

252
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda