Error: Failed to lookup view “./views/pug” in views directory “E:\FreeCodeCamp\Quality Assurance\boilerplate-advancednode\views”
I tried res.render(“pug”); and it is working but I still failed in the freecodecamp challenge. What should I do?
Error: Failed to lookup view “./views/pug” in views directory “E:\FreeCodeCamp\Quality Assurance\boilerplate-advancednode\views”
I tried res.render(“pug”); and it is working but I still failed in the freecodecamp challenge. What should I do?
After browsing through the forum, it gave me an idea and I actually solved it Here’s my code in server.js:
‘use strict’;
require(‘dotenv’).config();
const express = require(‘express’);
const myDB = require(‘./connection’);
const fccTesting = require(‘./freeCodeCamp/fcctesting.js’);
const app = express();
fccTesting(app); //For FCC testing purposes
app.set(‘view engine’, ‘pug’);
app.set(‘views’, ‘./views/pug’)
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(“index”);
});
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log('Listening on port ’ + PORT);
});
If you are encountering the same problem I did:
set
method that sets the views
property of your app
to point to the ./views/pug
directory which is under my ’ app.set(‘view engine’, ‘pug’);’