Working on the .env problem

Tell us what’s happening:
My code is below. I think I did it right but I am not sure why it is not working and am confused on if i should see Hello Json on the screen or in the terminal?

var express = require(‘express’);
var app = express();
console.log(“Hello World”);

app.get("/", function(req, res) {
res.sendFile(__dirname + “/views/index.html”);
});

app.use(express.static(__dirname + “/public”));

var responce = “HELLO JSON”.toUpperCase();

if (process.env.VAR_NAME === “allCaps”) {
response = “Hello Json”.toUpperCase();
} else {
response = “Hello Json”;
}

app.get("/json", (req, res) => {
res.json({
message: responce
});
});

Your code so far

Your browser information:

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

Challenge: Use the .env File

Link to the challenge:

this is not getting the right variable from the .env file

have you created the .env file?

Hey seth,

Would you mind sharing a link to your project code? It would be a lot easier to see. Otherwise, keep in mind: Even if you do share a link to your project code, others are not able to view .env files on Repl.it.

Thanks

No. I did not know you need to.

This is probably a dumb question but do i need to name the file process.env

no, the file should be named exactly .env

A post was split to a new topic: Headers Error in .env Challenge

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