Question about advanced node and express

Hi everybody, i’m studing this lesson, i inserted pug in the dependency in the package.json as this code:

"dependencies": {
    "pug@": "^3.0.0"
    "dotenv": "^8.2.0",
    "express": "^4.16.1",
    "mongodb": "^3.6.1"
  },

and this is my server.js code:

'use strict';
require('dotenv').config();
const express = require('express');
const myDB = require('./connection');
const fccTesting = require('./freeCodeCamp/fcctesting.js');

const app = express();

app.set('view engine', 'pug')


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.route('/').get((req, res) => {
  res.render('views/pug');
});

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

i think there are for sure some errors, i’m a beginner on node and express, i hope you could help me find these errors.

pug@ ->> pug

remove @

@ This notation is for console installation like this
npm install pug@3.0.0

not in the .json file

use @ as a break between dependencies and its version

"pug" : "^3.0.0"

ok, i’ve fixed it my package.json, but i think i have to do some changes in my server.js cause i got lots of errors in the console, can you please give some other hints? Thank you anyway

I’m not 100% sure this will work as is.
It’s probably wiser to preface it with the current working directory so you know you have the right path.

What’s the error you are experiencing?

Something like

res.render(process.cwd() + '/views/pug');

IIRC, “res.render()” doesn’t need the directory name, and the default directory name for template engine in express is “views”, so if you store a file named “template.pug”, you can render it by using this:

res.render("template");
1 Like

Ok, thank you all for the help i’m going to work on it

LOL there was the solution here!!! i’ve to read all the exercise for sure! :man_facepalming: