Basic Node and Express - Serve JSON on a Specific Route

Tell us what’s happening:

I’ve read forum posts on this and tried the code in the hint guide. That didn’t pass and my current code doesn’t pass. Seems straightforward and I don’t see what is wrong with the code. Can someone point me in the right direction, please? Here’s my code:

const express = require('express');
const app = express();

app.get("/", (req, res) => res.sendFile(__dirname + "/views/index.html"));
app.get("/json", (req, res) => res.json({"message": "Hello json"}));
app.use("/public", express.static(__dirname + "/public"));

###Your project link(s)

solution: https://freecodecam-boilerplate-x3lwnw7eym3.ws-us117.gitpod.io

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36 Edg/132.0.0.0

Challenge Information:

Basic Node and Express - Serve JSON on a Specific Route

what link are you submitting?

do you still have the export in your file?

can you share a snapshot of the workspace?

Here’s the snapshot link:
https://gitpod.io#snapshot/86acc10f-8f68-4ccc-90b6-4fde2cd7e9fe

The link I’m submitting is:
https://freecodecam-boilerplate-x3lwnw7eym3.ws-us117.gitpod.io/

BTW, I’ve moved on to the next step, which doesn’t pass either. :woman_shrugging:

I don’t understand your question:

how did you pass the previous steps? you need to submit the port link, the one from the preview

there is an export at the end of the myApp.js file, if you remove it it will not work anymore

As said, you just need to submit the correct URL.

https://3000-freecodecam-boilerplate-x3lwnw7eym3.ws-us117.gitpod.io/

Then your code is passing for me.

Thank you! Fortunately, I’m working on my local server, too, and the export code was still there, so I added it back into my Gitpod repo. Don’t know why I removed it. As far as using the wrong link, no idea where my head was at with that. :roll_eyes: At any rate, it passes now, so I can officially move ahead! Thanks again!

Thank you! Your response was very clear…much appreciated.

if you are using the local server, why aren’t you using the localhost link?

:laughing: Okay, so here’s how it went. I started the “Managing Packages with NPM” by reading through the local server guide (which was buried in the Gitpod guide) on how to set up on localhost. I passed those challenges by submitting my localhost link.

Then, when I got to “Basic Node and Express,” I was trying to use the same code base and nothing worked. My first hint that something was off should have been that the myApp.js file was missing, so I copied it from the ZIP file I downloaded on my first attempt at this. That’s when I went to Gitpod. It wasn’t until later, when I re-read the instructions in the first challenge and the info in the links that I realized I needed to clone another repository to work from for the “Basic Node and Express” challenges.

So, I suppose at this point, I could submit either a localhost link or a Gitpod link, since I’m doing both. I wanted the code on my local system for future reference. And I’ve never used Gitpod before, so thought it would be good to know. :woman_shrugging: