Basic Node and Express - Use the .env File

Tell us what’s happening:

hello,
I am facing a problem in this tutorial where my code seems to be working fine when i change the MESSAGE_STYLE value in the .env file, where if it is equal uppercase then the local will display {“messsage”:“HELLO JSON”} otherwise if the MESSAGE_STYLE is any other value then the local {“messsage”:“Hello json”} .

####################

my .env file:

MESSAGE_STYLE=uppercase

####################

myApp.js file:

require('dotenv').config();
let express = require('express');
let app = express();
app.use( 
    "/public", 
    express.static(__dirname + "/public")
    );
    console.log("Hello World");
    app.get("/", function(req, res){
    res.sendFile(__dirname + '/views/index.html');
});

app.get("/json", function(req, res){
    let msg;
    if(process.env.MESSAGE_STYLE === 'uppercase'){
         msg = "Hello json".toUpperCase();
    }
    else{
        msg = "Hello json";
    }
    res.json({messsage: msg});
});
 module.exports = app; 

####################

submission link:
http://localhost:3000/

####################

test result:
// running tests The response of the endpoint

/json should change according to the environment variable MESSAGE_STYLE

// tests completed

####################

emerging error:
The response of the endpoint /json should change according to the environment variable MESSAGE_STYLE

####################

###Your project link(s)

solution: http://localhost:3000

Your browser information:

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

Challenge Information:

Basic Node and Express - Use the .env File

I was able to pass the tutorial fortunately, by redoing the whole module from the start, that seemed to make it work.

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