Basic Node and Express - Use the .env File

Tell us what’s happening:

I wrote as directed on the
challenge and testing url with /json at the end brings correct response. But it is still rejecting my script

###Your project link(s)

solution: https://3000-freecodecam-boilerplate-i9nve6yfgee.ws-eu118.gitpod.io

Your browser information:

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

Challenge Information:

Basic Node and Express - Use the .env File

what is your code? please share that

require('dotenv').config()

let express = require('express');


app.get("/json",(req,res) => {
  if(process.env["MESSAGE_STYLE"] == "uppercase"){
    res.json({"message": "HELLO JSON"})
  } else{
    res.json({"message": "hello json"})
  }

})

do you have the line that creates app? let app = ... ?
do you have the export at the end of that file?

and what’s inside your .env file?


I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

app is created
const res = require(‘express/lib/response’);

let app = express();

don’t put the .env file inside a folder

Still getting Failed

It is resolved. instead of putting response in each if else statement. i saved the if else statement to message value and set response to give the value of message. And Also adding “;” at the end of Require(‘dotenv’).config()