javascript – Error: Cannot find module html

javascript – Error: Cannot find module html

I am assuming that test.html is a static file.To render static files use the static middleware like so.

app.use(express.static(path.join(__dirname, public)));

This tells express to look for static files in the public directory of the application.

Once you have specified this simply point your browser to the location of the file and it should display.

If however you want to render the views then you have to use the appropriate renderer for it.The list of renderes is defined in consolidate.Once you have decided which library to use just install it.I use mustache so here is a snippet of my config file

var engines = require(consolidate);

app.set(views, __dirname + /views);
app.engine(html, engines.mustache);
app.set(view engine, html);

What this does is tell express to

  • look for files to render in views directory

  • Render the files using mustache

  • The extension of the file is .html(you can use .mustache too)

Simple way is to use the EJS template engine for serving .html files. Put this line right next to your view engine setup:

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

javascript – Error: Cannot find module html

Install ejs if it is not.

npm install ejs

Then after just paste below two lines in your main file. (like app.js, main.js)

app.set(view engine, html);

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

Leave a Reply

Your email address will not be published.