Basic Node and Express - Use the .env File

Tell us what’s happening:

Please check my code, i can’t pass (use-the–env-file)

###Your project link(s)

solution: https://3000-freecodecam-boilerplate-madzgxfr6xo.ws-us114.gitpod.io

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36 Edg/126.0.0.0

Challenge Information:

Basic Node and Express - Use the .env File

Screenshot 2024-07-02 at 12.09.59 AM
my code so far

Hey can you format this code using the </> instead of a screen shot? Just click and paste the code in between.

i wonder if you should move the dotenv reference higher (to the top line) and retry?

require('dotenv').config();
let express = require('express');
let app = express();


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

console.log('Hello World')

app.get('/', function(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"});
      }
  
    });































 module.exports = app;

i guess it didn’t help? how about the .env file? Did you create it as they requested?

1 Like
  1. Do you have a .env file with the correct key/value?

  2. Did you remember to restart the server after making changes?


Your code is passing for me.

1 Like

ahhh
i created the file with a name
now i’ve passed the file
thanks for the help

1 Like

happened to have wrong file name
thank you for your help :smile: