Basic Node and Express - Use the .env File

I have used both the Replit and my local environment (VSCode w/cloned github challenge files) for this challenge. I have tried both the regular function notation and ES6 arrow function notation. Here are both versions below …


app.get('/json', function(req, res) {
  res.json({
    "message": "Hello json"
  })

app.get('/json', function(req, res) {
let message = 'Hello json';  
console.log(process.env.MESSAGE_STYLE, " <= message style");
  if (process.env.MESSAGE_STYLE == "uppercase") {
    message=message.toUpperCase();
  } else {
    message=message;
  }
res.json({'message': message});
});

  ... and ...

app.get('/json', (req, res) => {
let message = 'Hello json';
(process.env.MESSAGE_STYLE == 'uppercase') ? message=message.toUpperCase() : message=message; 
res.json({'message': message});
});

The ES6 version works (sometimes) while the “regular function syntax” version doesn’t. Is there an error in the “regular function syntax” version?
Also, there seems to be a recurring problem where in the “Webview” tab, I’m getting the “Repl Waking up…” message that takes several minutes to resolve, if it resolves at all. These unexpected behaviors make learning difficult as it becomes harder to know what was completed correctly and why, and what was done incorrectly and why.

[Your project link(s)] → (https://boilerplate-express-2.dthomas19.repl.co)

solution: http://localhost:3000/json

Your browser information:

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

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

Link to the challenge:

My issue here is that it lacks a closing curly brace and parenthesis.

But there is no reason why you can’t use either regular function or arrow function in this case.

For the replit waking up issue, the way I deal with it is I let it wake up fully first then immediately after I submit my replit to the fCC checker. This way I know it is still awake.

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