cluster1
cluster1

Reputation: 5752

Loading template-engines into node.js / express

Can someone explain me the following code please. Actually just the first two lines.

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

It confuses me.

The first line alone would make sense it me. I would say it connects the file-extension "html" to the engine nunjucks. So that the engine nunjucks is used when a file with the extension "hmtl" has to be processed. But what is then the purpose of the second line?

The two lines seem to be the same. It's just that the do the same thing in different notation. At least that way it seems to me.

Can someone clarify the coding-pattern for me?

Upvotes: 0

Views: 49

Answers (1)

Emmanuel Gabriel
Emmanuel Gabriel

Reputation: 107

  • The first approach is to map a different extension to this template engine.
  • The second approach is to set a default template engine in the app.

Upvotes: 2

Related Questions