BASIC NODE AND EXPRESS - How to get the stuff to do the things with the .env File

After spending roughly a day going through completing this exercise, I have come to some conclusions.

  1. This isn’t really a conclusion, but more of a peeve. FCC tells you to use replit (which I will NOT link because I like to actually help people finish what they are working on) which does not let you create a .env file. Not a big deal really, but they also do not provide any real guidance on how to handle this issue (I tried the secrets crap, it wouldn’t work and apparently nobody on the forum uses it either so don’t expect to find any tips here).
  2. My code wasn’t bad, it was a combination of non-compliant platforms (replit) and a bunch of I don’t know what (my console was red and yellow all over, don’t know what it was talking about but it was referencing errors (over 100) with the FCC script that checks your work.
  3. I found this on the intergoogler and used it on glitch.com (which allows .env files) and it worked and the exercise is completed.
var app = express();
console.log("Hello World")

app.get("/", function(req, res){
  res.sendFile(__dirname+ '/views/index.html');
  app.use(express.static(__dirname + "/public"));
})
app.get("/json", (req, res) => {
     if(process.env.MESSAGE_STYLE === "uppercase"){
       res.json({"message" : "HELLO JSON"});
     }
     res.json({"message" : "Hello json"});
   });
module.exports = app;

I hope this message finds you in good health and before you pull all of your hair out.

1 Like

I haven’t used replit. But I use this a lot: