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:

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 )

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

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

it doesn’t… Thank you

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