Tell us what’s happening:
Hi, I’m newbie and start learning Nodejs on freeCodeCamp. I’m at the lesson “https://www.freecodecamp.org/learn/apis-and-microservices/basic-node-and-express/use-the--env-file” and get stuck there. Please help me check my code and correct it. Thanks.
Your code so far
require('dotenv').config();
var express = require('express');
var app = express();
console.log("Hello World");
app.get("/json", function(req, res) {
if (process.env.MESSAGE_STYLE === "uppercase") {
res.send("{message: " + "Hello Json".toUpperCase() + "}");
} else {
res.send("{message: Hello Json");
}
});
app.use(express.static(__dirname + "/public"));
module.exports = app;
** Result message **
The response of the endpoint /json should change according to the environment variable MESSAGE_STYLE
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36
.
Challenge: Use the .env File
Link to the challenge: