Tell us what’s happening:
I have no ideea why this is not working. Tweaked solutions here and there. Created my .env file , added the correct code to it. No, freakin’ ideea. refreshed my browser more times than I can count.
Pls help. I’ve been stuck on this for the past 2 days. smh
Your code so far
require('dotenv').config();
var express = require('express');
var app = express();
// --> 7) Mount the Logger middleware here
// --> 11) Mount the body-parser middleware here
/** 1) Meet the node console. */
/*console.log("Hello World");
/** 2) A first working Express Server */
/*function(req, res) {
res.send('Hello Express');
}*/
/** 3) Serve an HTML file */
/*app.get('/', (req, res)=> {
res.sendFile(__dirname + '/views/index.html');
});*/
/** 4) Serve static assets */
/*app.use(express.static(__dirname + "/public"));*/
/** 5) serve JSON on a specific route */
/*
app.get('/json', function(req, res) {
let message = "Hello json"
if (process.env.MESSAGE_STYLE === 'uppercase' ) {
return message = "HELLO JSON";
}
res.json({
"message": message
});
});
*/
/** 6) Use the .env file to configure the app */
let msg =
process.env.MESSAGE_STYLE === "uppercase" ? "HELLO JSON" : "Hello json";
app.get("/json", (req, res) => res.json({ message: msg }));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36.
Could you please include the link to your project? It will be easier to debug, with it.
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.
I’ve searched long and wide throughout the forum but all the issues with this challenge were from glitch. Not repl.it .So I am not sure as to why it is not working. Even went as far as copying the solution and modifying it to match my code. But to no success. I’m starting to belive there is an issue with repl.it and not with the code.
I managed to pass with your code. I forked your app, and added a .env , but all the rest was your code. Could you ensure your .env file has this exact variable:
You definitely need to return something (always), and that is done with res.json. However, you should be returning something different, based on the value of process.env.MESSAGE_STYLE.
I’d change it but that’s what I have to return apparently . That’s what the challenge is . Idk , I feel like I’m acting all stupid and blind on this one …
Store the variable MESSAGE_STYLE=uppercase in the .env file. Then tell the GET /json route handler that you created in the last challenge to transform the response object’s message to uppercase if process.env.MESSAGE_STYLE equals uppercase . The response object should become {"message": "HELLO JSON"} .
I started from scratch with JavaScript . Completed the Basic guide. May I tell you that it’s starting to make a lot more sense now .Thank you for the suggestion!