Advanced Node and Express - Set up a Template Engine

Tell us what’s happening:

I can run it on Replit and locally, but tests fail, I can see it’s connected in the terminal when I give the link to the tester - I’ve used the exact code you gave me from Advanced Node and Express - I don’t know what I’m doing wrong.
Here are links to my github repo, and my replit, both are failing the tests. Please let me know what I am missing here, because I can’t figure it out.

https://a9d4db49-ded7-46e3-ac92-851bd7bc2c2f-00-1ew7ymkdcxghh.janeway.replit.dev/

Your code so far

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) => {
  // Change the response to render the Pug template
  res.render('index');
});

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36

Challenge Information:

Advanced Node and Express - Set up a Template Engine

open the console when you run the tests, what errors do you see there?

1 Like

I just reran the tests, here are the errors from the console that I’ve gotten, I’m going to look them up shortly and see what I can do to fix.

Access to fetch at 'http://localhost:3000/_api/package.json' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
VM6:4 
            
            
           GET http://localhost:3000/_api/package.json net::ERR_FAILED 200 (OK)
eval @ VM6:4
#a @ dom-test-evaluator.js:2
await in #a
handleMessage @ dom-test-evaluator.js:2
onmessage @ dom-test-evaluator.js:2
dom-test-evaluator.js:2 TypeError: Failed to fetch
    at eval (eval at #a (dom-test-evaluator.js:2:254989), <anonymous>:4:21)
    at #a (dom-test-evaluator.js:2:255335)
    at async DOMTestEvaluator.handleMessage (dom-test-evaluator.js:2:256038)
#a @ dom-test-evaluator.js:2
await in #a
handleMessage @ dom-test-evaluator.js:2
onmessage @ dom-test-evaluator.js:2
about:srcdoc:1 Access to fetch at 'http://localhost:3000/_api/app' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
VM7:4 
            
            
           GET http://localhost:3000/_api/app net::ERR_FAILED 200 (OK)
eval @ VM7:4
#a @ dom-test-evaluator.js:2
await in #a
handleMessage @ dom-test-evaluator.js:2
onmessage @ dom-test-evaluator.js:2
dom-test-evaluator.js:2 TypeError: Failed to fetch
    at eval (eval at #a (dom-test-evaluator.js:2:254989), <anonymous>:4:21)
    at #a (dom-test-evaluator.js:2:255335)
    at async DOMTestEvaluator.handleMessage (dom-test-evaluator.js:2:256038)
#a @ dom-test-evaluator.js:2
await in #a
handleMessage @ dom-test-evaluator.js:2
onmessage @ dom-test-evaluator.js:2
about:srcdoc:1 Access to fetch at 'http://localhost:3000/_api/app' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
VM8:4 
            
            
           GET http://localhost:3000/_api/app net::ERR_FAILED 200 (OK)
eval @ VM8:4
#a @ dom-test-evaluator.js:2
await in #a
handleMessage @ dom-test-evaluator.js:2
onmessage @ dom-test-evaluator.js:2
dom-test-evaluator.js:2 TypeError: Failed to fetch
    at eval (eval at #a (dom-test-evaluator.js:2:254989), <anonymous>:4:21)
    at #a (dom-test-evaluator.js:2:255335)
    at async DOMTestEvaluator.handleMessage (dom-test-evaluator.js:2:256038)
#a @ dom-test-evaluator.js:2
await in #a
handleMessage @ dom-test-evaluator.js:2
onmessage @ dom-test-evaluator.js:2
about:srcdoc:1 Access to fetch at 'http://localhost:3000/' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
VM9:4 
            
            
           GET http://localhost:3000/ net::ERR_FAILED 200 (OK)
eval @ VM9:4
#a @ dom-test-evaluator.js:2
await in #a
handleMessage @ dom-test-evaluator.js:2
onmessage @ dom-test-evaluator.js:2
dom-test-evaluator.js:2 TypeError: Failed to fetch
    at eval (eval at #a (dom-test-evaluator.js:2:254989), <anonymous>:4:21)
    at #a (dom-test-evaluator.js:2:255335)
    at async DOMTestEvaluator.handleMessage (dom-test-evaluator.js:2:256038)
#a @ dom-test-evaluator.js:2
await in #a
handleMessage @ dom-test-evaluator.js:2
onmessage @ dom-test-evaluator.js:2
about:srcdoc:1 Access to fetch at 'http://localhost:3000/' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
VM10:4 
            
            
           GET http://localhost:3000/ net::ERR_FAILED 200 (OK)
eval @ VM10:4
#a @ dom-test-evaluator.js:2
await in #a
handleMessage @ dom-test-evaluator.js:2
onmessage @ dom-test-evaluator.js:2
dom-test-evaluator.js:2 TypeError: Failed to fetch
    at eval (eval at #a (dom-test-evaluator.js:2:254989), <anonymous>:4:21)
    at #a (dom-test-evaluator.js:2:255335)
    at async DOMTestEvaluator.handleMessage (dom-test-evaluator.js:2:256038)

Got it, thank you for leading me down the right path!

const cors = require('cors');
app.use(cors());

was the fix, spent days on 2 lines of code. Lol, part of the process. Thanks again!