Using the .env file

So the issue I am having is that I seem not to be able to get why the code wont work. The following is what I have thus this far. I also created a .env file the new way Replit has us doing that by creating the key being ‘MESSAGE_STYLE’ and the key being ‘uppercase’. Now I don’t know why the constant is not being registered and called to implement the uppercase.

Any help is most welcome.
app.get(’/json’, (req, res) => {
const mySecret = process.env[‘MESSAGE_STYLE’];
let message = ‘Hello json’;
(mySecret == ‘uppercase’) ? message=message.toUpperCase() : message=message; res.json({‘message’: message});

});
``` ````

Your project link(s)

solution: https://replit.com/@mcclemz/boilerplate-express

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:

I’m getting a 502 on this and my own project.

I added the cors middleware package and used it in myApp.js and that seemed to fix it.

  1. Install the package using the Packages button in the sidebar.

  2. At the top of myApp.js bring it in and use the middleware

const cors = require('cors');
app.use(cors());

See if that works for you as well.


Edit: now it’s back to timing out and giving a 502. Sometimes Replit is just being weird. Try again later and see if it fixes itself.

As an aside. I would not suggest using a ternary the way you are with assignments and you should really format the code better.