abroroo
January 25, 2022, 2:52pm
#1
Couldn’t pass this section, although it is working fine on my localhost.
I am using local editor and localhost
Completed all the steps asked, installed dotenv npm package as well.
My code so far:
app.js
var express = require('express');
var app = express();
require('dotenv').config();
app.use(express.static(__dirname + '/public'));
app.use('/public', express.static(__dirname + '/public'));
app.get('/', (req, res) => {
res.sendFile(__dirname + '/views/index.html');
})
app.get('/json', (req, res) => {
let obj = {"message" : "Hello json"}
if (process.env.MESSAGE_STYLE = "uppercase") {
res.json(obj.message.toUpperCase());
} else {
res.json(obj.message);
}
})
.env file
MESSAGE_STYLE="uppercase"
Output is “HELLO JSON” on http://localhost:3000/json
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36
Challenge: Use the .env File
Link to the challenge:
abroroo:
message.toUpperCase()
Double check. What does ‘toUpperCase’ actually do? What are you supposed to return?
I don’t think that you are actually returning a json for an object in the specified format.
abroroo
January 26, 2022, 1:51pm
#3
Thank you!
I learned that toUpperCase returns a new string, and it doesn’t modify the original
So I did this
app.get('/json', (req, res) => {
let obj = {"message": "Hello json"};
if (process.env.MESSAGE_STYLE = "uppercase") {
obj.message = obj.message.toUpperCase();
}
res.json(obj);
})
localhost:3000/json output is this
{
* "message": "HELLO JSON"
}
What am I missing now?
Still can’t pass the test. It says
The response of the endpoint /json
should change according to the environment variable MESSAGE_STYLE
If you have a question about a specific challenge as it relates to your written code for that challenge, just click the Ask for Help button located on the challenge. It will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.
Thank you.
system
closed
July 28, 2022, 5:03am
#6
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.