Tell us what’s happening:
I’m quite stuck on this challenge and can’t tell if I’m missing a step or if there’s a bug that’s stopping me from passing the tests. Bear with me because I’m new at this, but here’s what I’ve tried so far:
The challenge says to store the variable MESSAGE_STYLE=uppercase in the .env file. I’m using the repl.it terminal to write the code and there is no .env file to be found. I tried creating one and added:
VAR_NAME=MESSAGE_STYLE;
MESSAGE_STYLE=uppercase;
There aren’t any instructions on how exactly to store the environment variable so my first question is how do I do that.
Next, I tried using the following to tell the GET /json route handler to transform the response object’s message to uppercase if process.env.MESSAGE_STYLE equals uppercase:
The boilerplate should not contain a .env file. So, it is expected that you create one.
.env files work as line-deliminated text. So, a ; (semi-colon) at the end is included in the value. To answer your first question, you have done most of that part correctly.
You have written two very different things here. The sentence is correct, the code does not reflect it.
I cannot tell exactly, without seeing your full code, but it looks like you are not responding correctly either. So, just to clarify:
// Setup route attached to app
app.route('/json').get((request, response) => {
// Set the message you want to send
const myResponseVariable = ...;
// Respond with the data:
response.json(myResponseVariable);
});
Sorry, I seem to have confused you with my previous code. My previous code was just an example, not what you need to pass this exercise.
Make sure you only have 1 of each route (eg. /json)
Ensure all of your logic for this 1 challenge is contained within the /json route.
To expand on this lesson as much as possible:
You are defining a new route for the app - /json
You are writing logic for this route, whereby the response depends on the MESSAGE_STYLE variable contained in the .env file
Variables within a .env file are accessed using process.env.VARIABLE_NAME
The response should be a JSON message with a message key.
When the endpoint (/json) is hit, the logic held within it will be executed. Any logic outside of the endpoint is only ever executed upon the first call to the file (server.js/myApp.js).
To clarify, for all intents and purposes, there is no difference between app.route('/').get(...) and app.get('/', ...).
Hope this is more clear.
If you are completely lost, I highly recommend resetting the code, and starting again. It would be very beneficial