It must be {"message":"HELLO JSON"}
am wrong ?
than where is the problem here ?
Why the FFC can’t have an access to the Secrets Environment Variables of Replit ?
It is secret… so only you can verify that you actually added the correct secret.
So how the FCC can verify if I’m using this Secret in wrong way ?
I don’t know that I understand what you are asking. If you choose to intentionally bypass the lesson and cheat, that’s your problem.
I don’t want to cheat and I didn’t said that , I want to pass it normally but the Test shows me this message and I still don’t know where Im wrong
The response of the endpoint
/json
should change according to the environment variable
MESSAGE_STYLE
Hello there,
In the background, the freeCodeCamp tests do have access to your process
(Nodejs runtime variable), because it is a part of your app, in the fcc-express-bground
package (REPLIT hides the node_modules folder with the package code, but you can see it installed in the package.json
file).
This package tests your app by changing the variable from uppercase
to a different value, and looks at your app output.
Now, what others have mentioned in this thread is that you need to:
a) Use the correct syntax for the app to work
b) Not use a global variable, for the logic state
Why is b
a problem? Read more here:
- .env not identified with Repl and not working on others - #2 by Sky020
- Help with the Use the .env File challenge - #31 by Sky020
Hope this helps
You fixed the case, but you move the variable out of the function again. With your current code as it is now…
Code
const mySecret = process.env['MESSAGE_STYLE']
var express = require('express');
var app = express();
app.use("/public", express.static(__dirname + "/public"));
app.get('/', (function(req,res) {
res.sendFile(__dirname + "/views/index.html");
} ));
app.get('/json', (function(req,res) {
if( mySecret === "uppercase" ){
res.json({"message" : "Hello json".toUpperCase() });
} else {
res.json({"message" : "Hello json" });
}
}))
…all you have to do is move the line const mySecret = process.env['MESSAGE_STYLE']
inside the handler.
Just in case this still isn’t clear.
Spoiler
var express = require('express');
var app = express();
app.use("/public", express.static(__dirname + "/public"));
app.get('/', (function(req, res) {
res.sendFile(__dirname + "/views/index.html");
}));
app.get('/json', (function(req, res) {
const mySecret = process.env['MESSAGE_STYLE']
if (mySecret === "uppercase") {
res.json({ "message": "Hello json".toUpperCase() });
} else {
res.json({ "message": "Hello json" });
}
}))
If that doesn’t work, then you didn’t set up the environment variable correctly.
You can check this answer above
I got the exact result they asked me for , the problem is the FCC doesn’t accept it , and I don’t know why ?
Any one can help me out this bug here it seems a problem in this platform , Im stuck for the past 24h looking for a hint
Please paste the link you are trying to submit, inside backticks like so:
`https://example-link`
Your code is still incorrect, because of:
I already did this and it didn’t wok and this is why :
https://boilerplate-express-1.smailove.repl.co/json
do not add the /json
part
just the link to the app, https://boilerplate-express-1.smailove.repl.co
Try reading again that, because you have not done what’s written there
The eror massege says
The response of the endpoint /json should change according to the environment variable MESSAGE_STYLE
so it must include the endpoint /json
I tried without the /json but still the same message
Plain and simple: This code will not work - is not correct
const mySecret = process.env['MESSAGE_STYLE']
...
app.get('/json', (function(req,res) {
if( mySecret === "uppercase" ){
res.json({"message" : "Hello json".toUpperCase() });
} else {
res.json({"message" : "Hello json" });
}
}))
It will not work, because of the reasons mentioned in most of the above replies.
if you mean declaring mySecret
inside the function well i tried this already and this was the result :