Unable to change response according to env -(node - express)

Tell us what’s happening:
Unable to get the required output. I’m not able to figure out why. I’ve tried res.send(), end(), .json(). Even if I get the correct output, it’s not being detected by the fcc test suite. Can anyone please point where I’m going wrong?

below is the project link

Your project link(s)

solution: https://replit.com/@sandeepgumaste/boilerplate-express-2

env file:

  "MESSAGE_STYLE": "uppercase"

myApp.js file:

const mySecret = process.env['MESSAGE_STYLE']
var express = require('express');
var app = express();
app.use("/public", express.static(__dirname + "/public"));
  // if(mySecret==='uppercase'){
  //   response = "Hello json".toUpperCase();
  // }else{
  //   response = "Hello json";
  // }
  // res.send({
  //   message: `${response}`
  // })
  res.send("Home page")
app.get("/json", (req, res) => {
    response = "Hello json".toUpperCase();
    response = "Hello json";
  return res.send({
    message: `${response}`

Your browser information:

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

Challenge: Use the .env File

Link to the challenge:

You need to access the environment variable inside the route handler (not the variable you have at the top). This process.env['MESSAGE_STYLE'] should be evaluated when the route is accessed.

And you should go back to using res.json (you don’t need to but I would still suggest you do that).

1 Like

It worked. Thank you very much.

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