Advanced Node and Express - Set up a Template Engine

Tell us what’s happening:

I have done the course, and i did it on gitpod.
I did npm install, and started the server with npm start. but when i submitted the link to freeCodeCamp, all tests are failing.

Here is my 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');
app.set('views', './views/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('index');
});

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

Output screenshot:

###Your project link(s)

solution: https://3000-freecodecam-boilerplate-rzzdlrtpwvc.ws-us120.gitpod.io

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:139.0) Gecko/20100101 Firefox/139.0

Challenge Information:

Advanced Node and Express - Set up a Template Engine

Hello, I am having the same probem. i dont know whats wrong


You need to open your own topic

If you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Get Help > Ask for Help button located on the challenge.

The Ask for Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.

Hello,
Yes i did that directly on the challenge page.

Hi @Ivankoe96

You don’t need to use npm install.

Start a new workspace.
After making changes use npm run start - the live view should refresh with a flicker.

Happy coding

Hi @Teller
I have tried creating a new workspace with FCC’s github repository:

and it automatically ran npm install and also npm run start because of the .gitpod.yml.
Still not passing.

I also tried cloning the repo, and pushing to my newly created repo, also still failing.

you need to stop the server and restart it after you make changes, or they will not be in the server

Hi @ILM

I did do that, you can see here on this link:

i have checked the code, and also did a quick search on google. Do you think i made a mistake? Because all tests are failing, even the number 1. Pug should be a dependency

if you want to share your workspace you need to share a snapshot Collaboration & Sharing of Gitpod workspaces - Gitpod Classic

Thank you for the clarification @ILM

Here is the snapshot link: Dashboard

I am not sure it is possible to solve at this time, if you open the browser console there are various errors that get generated when you run the tests

this I think is the issue about it: backend test runner does not set origin on fetch · Issue #60874 · freeCodeCamp/freeCodeCamp · GitHub

Hello @ILM,
I found out from the link you shared with me, that the CORS header is missing.
i have managed to successfully submited the link and passed all 5 tests with this addition to the code.

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

const app = express();

// add this CORS header
app.use((req, res, next) => {
  res.header('Access-Control-Allow-Origin', '*');
  res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
  res.header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
  next();
});

app.set('view engine', 'pug');
app.set('views', './views/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('index');
});

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

But this is only for the first step “Set up a Template Engine”, i haven’t tested this with the following tests.

Hope this helps.

1 Like

Thank you, it works perfectly now

@Darkwatch

Glad it worked!

1 Like

thanks a lot! finally someone’s pointing out how to fix it hahaha