Basic Node and Express - Use the .env File

Tell us what’s happening:

This is my code in myApp.js and I don’t know what’s wrong

let express = require(“express”);
let app = express();

app.use(“/public”, express.static(__dirname + “/public”));

app.get(“/”, (req, res) => {
res.sendFile(__dirname + “/views/index.html”);
});

app.get(“/json”, (req, res) => {
if (process.env[“MESSAGE_STYLE”] == “uppercase”) {
res.json({ message: “HELLO JSON” });
} else {
res.json({ message: “Hello json” });
}
});

module.exports = app;

###Your project link(s)

solution: Glitch :・゚✧

Your browser information:

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

Challenge Information:

Basic Node and Express - Use the .env File

code:

What do you need to require to use process.env?

I am doing this in glitch, otherwise I would require (‘dotenv’).config()

Have you tried requiring that in your code? I don’t use Glitch but it looks like Glitch just doesn’t display the node_modules folder in your editor.

1 Like

Thanks, that was the case!