Tell us what’s happening:
So I am having a problem passing the above mentioned challenge.
When I submit my solution, fcc says // running tests The response of the endpoint /json should change according to the environment variable MESSAGE_STYLE // tests completed
I am running this on my local machine (you can probably see that from the localhost link) and it works as the endpointhttp://localhost:3000/json
displays:
{
"message": "HELLO JSON"
}
It relatively easy, so am not sure why it isn’t passing.
my code is
let express = require('express');
require('dotenv').config();
let app = express();
let homeAbsolutePath = __dirname + "/views/index.html";
let stylesAbsolutePath = __dirname + '/public';
app.use('/public', express.static(stylesAbsolutePath));
app.get('/json', (req, res) => {
let msg = "hello json";
const secretWord = process.env.MESSAGE_STYLE;
if(secretWord === "uppercase"){
res.json({ "message": msg.toUpperCase() });
}else{
res.json({ "message": msg });
}
});
app.get('/', (req, res) => {
res.sendFile(homeAbsolutePath);
});
I have checked similar questions but most are unsolved or require submitting the correct replit link, so they don’t work for me.
NB: I am running this on locally as replit kept spinning and logging nothing since challenge one.
Your project link(s)
solution: http://localhost:3000
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36
Challenge: Basic Node and Express - Use the .env File
Link to the challenge: