Use the .env File - Replit. Cant submit and pass

I am have an awful lot of trouble with the Use the .env File question.

I have put together a solution in replit and used the SECRETS tab to set the variable.
My code works in replit but if I submit it to FFC, it does not work. I have read many forum comments but I can’t figure this out. Is the FFC grading not set up to handle the SECRETS tab? What is going on?

I have posted my code below. Also, here is the link:

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

const mySecret = process.env['MESSAGE_STYLE'];
    
app.get("/json", (req, res) => {
  var message = {"message": "Hello json"};
  if (mySecret=="uppercase"){
    message = {"message": "HELLO JSON"};
  }
    res.json(message);
});

 module.exports = app;

What URL are you submitting for the test? It is looking for the domain itself, so while my actual JSON response is at

https://boilerplate-express-1.tobiasparent.repl.co/json

the test wants to get

https://boilerplate-express-1.tobiasparent.repl.co

without the trailing /json.

1 Like

I post without the “/json”

as you define mySecret when you start the app, it is never going to change. You want the value of the environment variable when the endpoint is called

3 Likes

Thanks. That worked and I have submitted successfully.

code is now:

app.get("/json", (req, res) => {
var message = {“message”: “Hello json”};
if (process.env[‘MESSAGE_STYLE’]==“uppercase”){
message = {“message”: “HELLO JSON”};
}
res.json(message);
});

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.