Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

248
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!