Basic Node and Express - Use the .env File

Tell us what’s happening:
i have problem with this exercise, i’ve done setup env key = MESSAGE_STYLE, value = uppercase

and i write the code same like hint but alwas error, i can’t find where is problem.

this my code :

type or paste code here
let express = require('express');
let app = express();
require('dotenv').config()

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

app.get("/", (req, res) => {
  res.sendFile(__dirname + "/views/index.html");
});

app.get("/json", (req, res) => {
  res.json({
    message: "Hello json"
  });
});


app.get("/json", (req, res) => {
  var response = "Hello World".toUpperCase();
  const mySecret = process.env['MESSAGE_STYLE'];

  if (process.env.VAR_NAME === "allCaps") {
    response = "Hello World".toUpperCase();
  } else {
    response = "Hello World";
  }
})




console.log("Hello World");



































module.exports = app;

solution: boilerplate-express (2) - Replit

Your browser information:

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

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

Link to the challenge:

You missed the key instruction:

Then, in the /json GET route handler you created in the last challenge

Also, even if you figure out where to put the code, the code you wrote below is not what the instructions tell you to do either.

  var response = "Hello World".toUpperCase();
  const mySecret = process.env['MESSAGE_STYLE'];

  if (process.env.VAR_NAME === "allCaps") {
    response = "Hello World".toUpperCase();
  } else {
    response = "Hello World";
  }

The above code would assign the value HELLO WORLD to the response variable if the environment variable named VAR_NAME has the value allCaps. Otherwise, the value Hello World would be assigned to the response variable. No where in the instructions does tells you to write code to do this.

thanks sir, the problem had been solved

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