Basic Node and Express - Use the .env File

Tell us what’s happening:

Please someone provide me with the solution. I have tried each and every way but the solution is not getting accepted.

###Your project link(s)

solution: https://3000-freecodecam-boilerplate-dnujqjydzsh.ws-us110.gitpod.io

Your browser information:

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

Challenge Information:

Basic Node and Express - Use the .env File

We cannot write the solution for you. Please talk to us about how this problem is confusing. Thanks

Hi,
I am trying to solve the problem and come up with the solution which is running well in the browser but is not accepting by the freecodecamp as t is displaying the error ,“/json response should change according to environment variable MESSAGE_STYLE”.

Pasting the link of both the problem and the solution.
problem :- https://www.freecodecamp.org/learn/back-end-development-and-apis/basic-node-and-express/use-the--env-file

Solution :- .env file contains :- MESSAGE_STYLE=uppercase
myApp.js file contains :-
let express = require(‘express’);
let app = express();
require(‘dotenv’).config()
app.use(“/public”, express.static(__dirname + ‘/public’))

console.log(‘Hello World’)

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

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

module.exports = app;

Thanks!

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