Tell us what’s happening:
I cannot pass the challenge even though I have done everything right in repl.it
I have already installed dotenv package and also .env file but freecodecamp still marks it as fail. And I can access the endpoint successfully as well.
Below is my code in myApp.js
Your code so far
require('dotenv').config();
var express = require('express');
var app = express();
//middleware for all requests stuff (root level)
app.use(express.static(__dirname + "/public"));
app.get("/", (req, res)=> {
res.sendFile(__dirname + "/views/index.html")
})
app.get("/json", (req, res) => {
let message = (process.env.MESSAGE_STYLE=="uppercase") ?
"HELLO JSON":
"Hello json"
res.json({"message":message})
})
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.146 Safari/537.36.
I think that the problem is that you are hard-coding the response object. You need to use JS to manipulate the response into uppercase when your dotenv variable is set. Don’t hardcode “HELLO JSON”.
From instructions (important in bold):
Store the variable MESSAGE_STYLE=uppercase in the .env file. Then tell the GET /json route handler that you created in the last challenge to transform the response object’s message to uppercase if process.env.MESSAGE_STYLE equals uppercase . The response object should become {"message": "HELLO JSON"} .
I’ve already used toUpperCase() function but it still didn’t work. When I submit the answer, it shows this syntax error: “SyntaxError: Unexpected token < in JSON at position 0”
I don’t know where that syntax error is coming from. I’m going to work through that portion of the curriculum real quick again since when I did it it was on glitch and see if I can get things to pass… if so then I’ll diff all of the files and see what is different
We are still trying to find the source of the issue, because some Campers experience it, whilst others do not.
EDIT: As an update, code that passed 3 days ago is now failing, and this challenge has not been changed since, neither has the testing. So, I suspect it might be related to Repl.it
I can confirm after going through the updated curriculum that I am encountering the same issue. Do we have data on who has passed it and when they forked the project? I’m suspecting there was a change in the dependency chain somewhere.