.env file not registering when using Replit?

What’s happening:
I think I have read the instructions and understood them to be:

  1. Create an .env file in the root of the project and using Replit, I used ‘Secrets’ and the ‘key:value’ pair for the mySecret constant is ‘MESSAGE_STYLE: uppercase’ respectively.
  2. Now on to the requirements of the question- to transform the response object’s message to either, {"message": "Hello json"} or {"message": "HELLO JSON"} , depending on the MESSAGE_STYLE value. Note the capital ‘H’ and small ‘j’ on the lower case out come.

My solution is a follows:

var express = require('express');
//const cors = require('cors');

//const dotenv = require('dotenv');
//dotenv.config({path: '${__dirname}/ENV'});
var app = express();

app.use("/public",express.static(__dirname + "/public"));
console.log("Hello World")

app.get("/", (req, res)=> {
  res.sendFile(__dirname + "/views/index.html");

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

 module.exports = app;

Your project link(s)

solution: https://replit.com/@spirit-spirited/boilerplate-express-1

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/537.36 Edg/96.0.1054.53

Challenge: Use the .env File

Link to the challenge:

Given the above, the grading system of fcc marks it wrong. I haven’t now a . clue where I could have gotten this wrong. I am supposed to return the upperCase variant of the response but it seems like the environment variable is completely being ignored.

Take a closer look at the code in the else block.

Many thanks for your eagle eye mate!!! That was it.

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