Solution link/challenge not working

Hello everyone!

I’m trying to complete this challenge but it seems like the tests are not working.
So the challenge ask me to return a json message written in all caps, which my app returns, but apparently not for the tests. I tried multiple solutions and still cant get it done. Anyone knows how to proceed?

Challenge

This is my code

var express = require('express');
var app = express();
const mySecret = process.env['MESSAGE_STYLE']

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

app.get('/json', function(req,res){
  const helloJSON = 'Hello json';
  let message;
  if(mySecret ==='uppercase'){
    message= helloJSON.toUpperCase();
  }else{
    message= helloJSON
  }
  const data={
   "message": message   
  };
  res.json(data);
})

app.get('/',function(req,res){
  const filePath= __dirname+'/views/index.html';
  console.log(filePath)
  res.sendFile(filePath)
})

module.exports = app;

And this is my solution link, which returns the statement asked in the challenge

https://boilerplate-express.igornix.repl.co/

It’s a ‘best practice’ to assume that your code is broken. Even my code that seems to work right I assume is broken in some way.

Here you are checking the value of the environment variable out in the global space. But that means it is impossible for your GET to respond to changes in this environment variable after the application starts. The test checks your app by changing this environment variable.

I’ve tried without it, still doesn’t work.

I don’t understand what ‘without’ means… You need to get the value out of the environment variable somewhere in your code.

I’m using repl, so the value is inside the 'secretlab ’ section

I’ve also seen videos with exact same code and it worked for them

If the ‘exact same code’ has the line I highlighted outside of the GET request function, then that code will fail the test suite.

Tried inside as well.

What des that code look like? It’s hard for me to comment on code you didn’t show, lol

Minute 1 10, same code, works for him not for me Back-end Development and APIs - FreeCodeCamp Tutorial - YouTube

Is that exactly, precisely, character-for-character identical to the code in your original post?

Again, it’s hard for me to help you fix your code when you don’t show me your code. I can pass with my code, but that doesn’t help me help you fix your code.

Yes it is, i will post it again. By the way, if i test it myself on my browser by going to the link and adding ‘/json’ at the end of the link i get my solution correctly, with all the solutions ive tried it works, but not for FCC

var express = require('express');
var app = express();
const mySecret = process.env['MESSAGE_STYLE']

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

app.get('/json', function(req,res){
  const helloJSON = 'Hello json';
  let message;
  if(mySecret ==='uppercase'){
    message= helloJSON.toUpperCase();
  }else{
    message= helloJSON
  }
  const data={
   "message": message   
  };
  res.json(data);
})

app.get('/',function(req,res){
  const filePath= __dirname+'/views/index.html';
  console.log(filePath)
  res.sendFile(filePath)
})

 module.exports = app;

Ok. Again, this line cannot go here. You cannot check this value in the global space and get the correct behavior.

Ive added it to the /json block, still works! this is the link to try it yourself! https://boilerplate-express.igornix.repl.co/json

And what does the code look like with that line moved?

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


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

app.get('/json', function(req,res){
  const helloJSON = 'Hello json';
  const mySecret = process.env['MESSAGE_STYLE']
  let message;
  if(mySecret ==='uppercase'){
    message= helloJSON.toUpperCase();
  }else{
    message= helloJSON
  }
  const data={
   "message": message   
  };
  res.json(data);
})

app.get('/',function(req,res){
  const filePath= __dirname+'/views/index.html';
  console.log(filePath)
  res.sendFile(filePath)
})

Thank you.

Where did this line go?

module.exports = app;

Still in the code, didnt added just to make things easier

You are not supposed to submit the URL with the /json path.

This passes for me:

https://boilerplate-express.igornix.repl.co/

It doesnt for me! thats the issue :c

1 Like