Basic Node and Express - Use the .env File

Tell us what’s happening:
Describe your issue in detail here.
As my code works fine but i was just unable to pass the test of freecodecamp.

link :

let express = require('express');
let app = express();
const absolutePath = __dirname + "/views/index.html"

if ( process.env.MESSAGE_STYLE === "uppercase") {
  response = "Hello Json".toUpperCase();
} else {
  response = "Hello Json"
//app.use(express.static(__dirname + "/public"))
app.use('/public', express.static(__dirname + "/public"))

app.get('/', function(req, res) {

app.get('/json', function(req, res) {

module.exports = app;

Your project link(s)

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36

Challenge: Basic Node and Express - Use the .env File

Link to the challenge:

well in the else statement Hello Json shoulde be Hello json.are you using replit or doing locally?

But thanks for your help

You can’t have the if/else outside the route handler as the environment variable needs to be re-evaluated.

Then, in the /json GET route handler you created in the last challenge access process.env.MESSAGE_STYLE

Also, please link to your Replit.

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