Tell us what’s happening:
I can’t get this to pass with my solution or anyone else’s in the forums.
app.get(‘/json’, (req, res) => {
var message="hello json"
if ( process.env.MESSAGE_STYLE === "uppercase" ) {
message = message.toUpperCase();
}
res.json({"message": message});
});
###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/124.0.0.0 Safari/537.36
Challenge Information:
Basic Node and Express - Use the .env File
The issue may be this:
The response object should either be {"message": "Hello json"} or {"message": "HELLO JSON"} , depending on the MESSAGE_STYLE value.
Your lowercase value for message does not match the requirements.
Thank you for pointing that out, but unfortunately that is not the issue. The main issue is the function is not changing the message to the capitalized version when I add the json path to the simple browser. Here is all my code in case the error is somewhere else.
let express = require(‘express’);
let app = express();
console.log(‘Hello World’);
app.get(‘/’, (req, res) => {
res.sendFile(__dirname + ‘/views/index.html’);
});
app.use(‘/’, (req, res, next) => {
console.log(req.method + ’ ’ + req.path + ’ - ’ + req.ip);
next();
});
app.use(‘/public’, express.static(__dirname + ‘/public’));
app.get(‘/json’, (req, res) => {
var message="Hello json";
if ( process.env.MESSAGE_STYLE === "uppercase" ) {
message = message.toUpperCase();
};
res.json({"message": message});
});
ILM
May 12, 2024, 2:50pm
4
have you restarted the server after your changes?
Yes. Here is my .env file variable: MESSAGE_STYLE=uppercase
This I have experimented adding and moving a “;” around after the variable and can’t get any iteration to work.
ILM
May 12, 2024, 2:55pm
6
absolutely no ; in there
do you have dotenv? or something equivalent?
That was it, I misread the bottom paragraph of the lesson.
Thank you SO much haha.