Tell us what’s happening:
please help me!
I’ve been stuck on this challenge for days and can’t get it to pass. I’ve tried almost every solution available on the forum and the web.
- changing dot notation to bracket notation for accessing the variable.
- changing the message instead of using the toUpperCase() method.
- saving the variable in a const instead of accessing it directly in the if condition.
- declaring a response object and changing the message later.
- updating the packages already installed by the GitHub repo.
none of the above worked for me.
I’m using app.cyclic.sh as my free host and I’m setting the MESSAGE_STYLE variable inside the variables section. I would put every piece of information I think is necessary here.
I would really appreciate your help, I desperately need the challenge to pass as it’s really influential on my career. thanks a lot!
Your project link(s)
solution:
require('dotenv').config();
var express = require('express');
var app = express();
// console.log('Hello World');
// app.get("/", (req, res) => {
// res.send("Hello Express");
// });
app.use("/public", express.static(__dirname + "/public"));
app.get("/",(req,res)=>res.sendFile(__dirname + '/views/index.html'));
app.get("/json", (req,res) => {
const mySecret = process.env['MESSAGE_STYLE']
if (mySecret === "uppercase") {
res.json({
"message": "HELLO JSON"
});
}
else {
res.json({
"message": "Hello json"
});
}
});
// This would be part of the basic setup of an Express app
// but to allow FCC to run tests, the server is already active
/** app.listen(process.env.PORT || 3000 ); */
//---------- DO NOT EDIT BELOW THIS LINE --------------------
module.exports = app;
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36
Challenge: Basic Node and Express - Use the .env File
Link to the challenge: