Basic Node and Express - Use the .env File

Tell us what’s happening:
Hello, I don’t know how the code should look like. :s I’m using replit and added the key as secret but maybe end up deleting something important in the process bcs something is wrong.

my code so far:

https://replit.com/join/dkioljgcez-aurea94


let express = require('express');
let app = express();
console.log("Hello World");
app.get("/json", function(req, res) {
  res.json({"message": "Hello World"});
app.use("/public", express.static(__dirname + "/public"));
  
const mySecret = process.env['MESSAGE_STYLE']

  
});

response:
Error: Cannot find module ‘/home/runner/boilerplate-express/index.js’
Require stack:

  • /nix/store/bg1bhjsq967dzpkbbamzsrwzazc7r7y4-prybar-nodejs-0.0.0-24a859a/prybar_assets/nodejs/module-context-hook.js
  • /tmp/prybar-nodejs-3084944795.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.resolve (node:internal/modules/cjs/helpers:108:19)
    Describe your issue in detail here.

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

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

Link to the challenge:

Can you post a link to your project code? That would make it easier to test things out. Thanks.

First of all, this line should not be inside this callback. It should be located just below let app = epxress();

Second, your /json route will only ever return {"message": "Hello World"}. Is that what the challenge wants you to do?

You create this variable but never use it in any way.

1 Like

Yes! code

Thank you very much!

Ok, thank you! So, “Hello World” should change to upper case ( the value of the variable MESSAGE_STYLE is uppercase )

Are you sure about this string?

"
The response of the endpoint /json should change according to the environment variable MESSAGE_STYLE"

That’s not “Hello World”? I don’t know

Where in the instructions does it tell you to use Hello World in the response?

it doesn’t… Thank you