Basic Node and Express - Use the .env File

Tell us what’s happening:

The response of the endpoint /json should change according to the environment variable MESSAGE_STYLE. This was my test case error. I don’t know how it occured. Help me solve it.

###Your project link(s)


Your browser information:

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

Challenge Information:

Basic Node and Express - Use the .env File

what is your code? did you restart the server after saving your changes?

Code for the respective files

.env file: -



let express = require(‘express’);
let app = express();

// console.log(“Hello World”);

app.get(“/”, (req,res) => {
res.sendFile(__dirname + “/views/index.html”)

// Assets at the /public route
app.use(‘/public’, express.static(__dirname + ‘/public’));

app.get(‘/json’, (req, res) => {
var response;
if (process.env.MESSAGE_STYLE) {
response = {“message”: “HELLO JSON”}
} else {
response = {“message”: “Hello json”}

These are the codes for the respective challenge. Help me rectify the test case error.

You need to explicitly check if the value for MESSAGE_STYLE is ‘uppercase’ (or not). This if statement only checks that the MESSAGE_STYLE variable exists, not what its value is.

Ok, I got it a few minutes back. But thanks for the help…

1 Like