Basic Node and Express - Use the .env File

I cant pass the challenge

doing this challenge using a local pc
solution: http://localhost:3000

Your browser information:

myApp.js code

let express = require('express');
let app = express();
console.log("Hello World");
const note = {
  "message":"Hello json"
};
app.get('/', (rq, rs) => {

  console.log( "Hello World" );
  rs.sendFile( __dirname + '/views/index.html' );
  
});

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

app.get('/json', (rq, rs) => {

  if(process.env.MESSAGE_STYLE == 'uppercase'){

    note.message = note.message.toUpperCase();
    
  };

  rs.json(note);
  
});

.env

MESSAGE_STYLE=uppercase

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

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

Link to the challenge:


image

Why is this a global variable? No need to pollute the global variable space here. Using the global space means separate calls against the API endpoint are related, which is causing your test to fail.

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