According to the requirement of the question, I have already import ‘dotenv’ to the environment and write a ifelse to control the upper case and lower case of ‘Hello Json’. However, when I ran the code in Replit, and send the link to the course page in freecodecamp, error message was still popped up. Is there any way to solve it?
The code and the link to Replit are attached as below:’
var express = require('express');
var app = express();
require('dotenv').config();
app.use("/public", express.static(__dirname +
"/public"))
app.get("/", (req, res) => {
res.sendFile(__dirname + "/views/index.html")
})
app.get('/json', (req, res) => {
const mySecret = process.env['MESSAGE_STYLE']; // Access inside the route handler
if (mySecret === "uppercase") {
res.json({"message": "HELLO JSON"});
} else {
res.json({"message": "Hello Json"});
}
});
let PORT = process.env.PORT || 3001;
module.exports = app;
myApp.js - boilerplate-express - Replit
The error message is as below: