I feel like I’ve done everything correctly on this exercise, but it is still not passing. I feel like it’s a simple fix but I’ve been stuck on it for over an hour.
let express = require('express');
let app = express();
console.log("Hello World");
app.get("/", function(req, res) {
const absPath = __dirname + "/views/index.html";
res.sendFile(absPath);
})
app.use("/public", express.static(__dirname + "/public"));
//this part right here
app.get("/json", function(req, res) {
res.json({"message": "Hello json"})
})
I have done npm install and npm start. It is listening on the proper port, but it is still not passing the tests. Could someone point me in the right direction?
What is the exact error message you get? Additionally are you using Repl.it or local? I had difficulty a really long time getting Repl.it to recognize the answers for my attempt at it. Additionally local can be weird because of CORS issues.
My code looks exactly like the FCC hint / answer, so idk what is wrong. Maybe there is some boilerplate code that is missing or I’m leaving out something that was never explained in the instructions.
This code says that if a client sends a get request to the /json path on this web server, send a JSON object consisting of a message string set to “Hello json”.
The .env lesson is actually the next exercise after this, but it doesn’t mention anything about using or needing .env to run things locally. It just teaches how to store and access global variables from an .env file, and then has you format the response message to uppercase depending on the value of the MESSAGE_STYLE variable.
But here is what my something.env file looks like.
MESSAGE_STYLE=uppercase
And here is my myApp.js file after the .env lesson.
Pardon me, but the .env file is not actually mentioned in this exercise. It is surprising to see this individual get an “[Error:Not Found]” though. The only browser it works properly is in Google Chrome. The other browsers seem to be more properly locked down, which I don’t know if it is a good or bad thing. Additionally the error I get in other browsers is this
I tried it on replit but I am still getting the same error. I’m not sure if I entered the URL properly. I used the actual replit page URL, and then I published the replit and tried copying the URL they gave me. Neither of them are passing the tests. Unfortunately.
Hi, I’m using Replit, and I’m still getting errors. I’m not sure what exactly the problem is but whenever I type /json in the web view, it returns not found
let express = require('express');
let app = express();
app.get("/json", function(req, res) {
res.json({"message": "Hello json"})
})