Tell us whatās happening:
I am stuck on this stupid problem for months now. Itās trivially simple, but I am unable to pass it. I donāt know if this is a bug in my code, or a bug with FCC.
The challenge: https://www.freecodecamp.org/learn/apis-and-microservices/basic-node-and-express/use-the--env-file
My code: https://glitch.com/~eastern-earthy-rake
As you can see at https://glitch.com/~eastern-earthy-rake/json , my code does post HELLO JSON in uppercase.
I get the error: The response of the endpoint /json
should change according to the environment variable MESSAGE_STYLE
What am I doing wrong here?
Your code so far
let message = {āmessageā: āHello Jsonā}
/** 6) Use the .env file to configure the app */
app.get(ā/jsonā, (req, res)=> {
if (process.env.MESSAGE_STYLE === āuppercaseā) {
res.json ({āmessageā: āHELLO JSONā})
} else {
res.json (message)}
})
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36
.
Challenge: Use the .env File
Link to the challenge:
Learn to code. Build projects. Earn certifications.Since 2015, 40,000 graduates have gotten jobs at tech companies including Google, Apple, Amazon, and Microsoft.
1 Like
Try this one:
app.get(ā/jsonā, (req, res)=> {
if (process.env.MESSAGE_STYLE === āuppercaseā) {
res.json ({āmessageā: āHELLO JSONā})
}
res.json (message)
})
1 Like
Nope, it doesnāt work. I get the same error.
I had posted about my problems with this challenge in June. Iām still stuck on this challenge.
Tell us whatās happening:
Iām getting an error in this challenge even though my solution is correct.
[image]
What I get when i change the value of MESSAGE_STYLE:
[image]
[image]
Your code so far
My code is here: https://eastern-earthy-rake.glitch.me
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Safari/537.36.
Challenge: Use the .env File
Link to the challenge:
1 Like
Try now:
var express = require('express');
var app = express();
var message = {"message":"Hello json"}
app.get("/json", (req, res) => {
if (process.env.MESSAGE_STYLE === "uppercase") {
res.json ({"message": "HELLO JSON"})
}
res.json (message)
})
(damn i hate the formatting shortcuts here XD)
But just to be clear, your code looks fine (although Im no expert) itās a matter of giving the algorithm what he wants.
If it does not pass, would you let me know whats your .env
file like?
1 Like
Screenshot of my .env file:
I donāt know exactly whats that, but I would create a simple .env
file in your directory, just next to the app.js
1 Like
Can you link me to the repl? if thatās possible, so I can see your files
1 Like
Thatās not what I mean. But the page where youāre actually writing the code (or maybe there are more ways to use glitch than I knew of).
1 Like
Something like this https://repl.it/@misterybodon/boilerplate-express
also, check out how I approach the problem and see if weāre doing similar
1 Like
I tried to submit your solution, and I get the same error. Does this happen to you?
lasjorg
August 13, 2020, 9:52pm
#14
You need to update the fCC dependency in your project. Remove the fcc-express-bground-pkg.git
package and then add it back again.
Delete this line from package.json
"fcc-express-bground": "https://github.com/freeCodeCamp/fcc-express-bground-pkg.git"
Wait for it to uninstall, then add it back (put back the line you remove) and let it install. Now submit the project.
1 Like
Thats not the link for the solution, only for the repl.
This is the link:
https://boilerplate-express.misterybodon.repl.co
yes as @lasjorg says thats also part of the problem as can be checked using
> npm outdate
//output
Package Current Wanted Latest Location
fcc-express-bground 0.0.5 git git fcc-learn-node-with-express
(but they should tell this in the exercise description)
I believe npm update
should do, though. Or maybe not?
2 Likes
Thanks for the assist. You cannot imagine how frustrating it has been to deal with this challenge. I gave up on the whole track, worked on a different certification, came back after a few months again to thisā¦
Youāre welcome and am quite sad about that, checked out your profile and saw the question many times therein. Feel free to ask me in a message any other time. Though I wasnāt that helpful.
Good luck!
1 Like
lasjorg
August 13, 2020, 10:10pm
#19
@slashgod Good to hear, sorry for the inconvenience. Happy coding.
Just as an FYI. This issue will affect anyone that has started the project before the package was updated. The update to the package was made to deal with a recent issue with Glitch. I only knew this was the issue because I recognized the console error and I made the PR with the fix.
1 Like
anon10002461:
var express = require('express');
var app = express();
var message = {"message":"Hello json"}
app.get("/json", (req, res) => {
if (process.env.MESSAGE_STYLE === "uppercase") {
res.json ({"message": "HELLO JSON"})
}
res.json (message)
})
Thanks. It worked. I was stuck too.