Basic Node and Express - Use the .env File

Tell us what’s happening:

Need help with using the .env challenge .I don’t understand why this isn’t passing. It generates the intended result every time

###Your project link(s)

solution: https://3000-freecodecam-boilerplate-6wq1a0vpliz.ws-eu116.gitpod.io

Your browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:130.0) Gecko/20100101 Firefox/130.0

Challenge Information:

Basic Node and Express - Use the .env File

please post the full code and discuss where you placed the .env file

Hello , here is my json get method

app.get(“/json”, function(req,res){
if (process.env.MESSAGE_STYLE === “uppercase”){
res.json(
{ “message” : “hello json”.toUpperCase()}
)
}
})

and here is my .env file

MESSAGE_STYLE=uppercase

my .env file path is /workspace/boilerplate-express/.env

You must add the dotenv package mentioned by the challenge as testing on gitpod needs it.

Please share all the code next time if you are still stuck.

Ps. What does your code do if the value is not uppercase?

I have the dotenv package ,

let express = require('express');
require("dotenv").config()
let app = express();
let static = express.static(__dirname + "/public")
app.use("/public",static)
app.get("/", function (req, res){
    path = __dirname + "/views/index.html"
    res.sendFile(path);
}
)
app.get("/json", function(req,res){
    if (process.env.MESSAGE_STYLE === "uppercase"){
        res.json(
            { "message" : "hello json".toUpperCase()}
        )   
}   
})


    
    
// function hello(req,res) {
//     res.send("Hello Express");
// }
// console.log("Hello world")

module.exports = app;

should I add a else for my if statement …

I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

i think you should in case the test needs that.