Advanced Node and Express - Set up a Template Engine - Solution

What is your hint or solution suggestion?

Challenge: Set up a Template Engine

Link to the challenge:


Install pug package using - npm i -D pug

Add the following code to server.js

"use strict";

const express = require("express");
const fccTesting = require("./freeCodeCamp/fcctesting.js");
const pug = require('pug');
const app = express();

fccTesting(app); //For FCC testing purposes
app.use("/public", express.static(process.cwd() + "/public"));
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.set('view engine', 'Pug');

app.route("/").get((req, res) => {
  //Change the response to render the Pug template
  res.render(__dirname+'/views/pug/index.pug');
  //res.send(`Pug template is not defined.`);
});

app.listen(process.env.PORT || 3000, () => {
  console.log("Listening on port " + process.env.PORT);
});

For passing the test pug should be a dependency add “pug”: “2.0.0-beta11” in package.json dependencies. Your dependencies should look like this -

 "dependencies": {
    "express": "^4.16.1",
    "cors": "^2.8.1",
    "pug": "2.0.0-beta11"
  },