I Don't understand what's wrong with my code

Tell us what’s happening:

My solution works and does exactly what is asked in the challenge, yet freecodecamp doesn’t agree.

here is my code:

var express = require('express');
var app = express();


console.log("Hello World")

app.get("/", (req,res)=> res.sendFile(__dirname + "/views/index.html"))

app.use('/public', express.static(__dirname + "/public"))

app.get("/json", function(req,res){
  if (process.env.MESSAGE_STYLE === "uppercase") {
  response = "Hello Json".toUpperCase();
} else {
  response = "Hello Json";
 res.json({"message": response})

In my .env file I have this :


Your project link(s)

solution: https://boilerplate-express.rflowturing.repl.co/json

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 11_2_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36.

Challenge: Use the .env File

Link to the challenge:

Welcome, wreip.

You should not submit anything but the root URL to your app. That is, do not include any endpoints (/json), when you submit.

Hope this clarifies

When I test your service, I get:

// running tests
The response of the endpoint /json should change according to the environment variable MESSAGE_STYLE
// tests completed

So, it doesn’t just need to work if the env variable is set to upper case, but if its not. The instructions say:

Then, in the GET /json route handler that you created in the last challenge…

When I look in that lesson, I see the message is "Hello json". But your default message here is "Hello Json".

Do you see the subtle difference? That might be a problem.

Thank you for replying Sky020,

I am not submitting the endpoint, the problem is somewhere else :slight_smile:

Thank you Kevin,

You spotted the mistake, it was subtle haha I needed to write json and not Json in the default message.


Yup, these are the mistakes that drive us crazy. We’ve all been there.

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