Process.env problem

Tell us what’s happening:
https://boilerplate-express.dletulle.repl.co/json
Inside my Repl.it I created the file “process.env” and the only line in it is:
MESSAGE_STYLE=uppercase

I’ve tried restarting the server, but the code still wont become uppercase.
I’ve even tried copying code from others which have completed the challenge and even copied the code from the solution, but it doesn’t work.
Any idea what I’m missing here?

var express = require('express');
var app = express();

console.log("Hello World")
/*
app.get("/", (req, res) => {
  res.send("Hello Express");
});
*/

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

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

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

Your project link(s)

solution: https://boilerplate-express.dletulle.repl.co/json

Your browser information:

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

Challenge: Use the .env File

Link to the challenge:

I cant see your full project code… although i notice you do not have

require("dotenv").config();

some other things I noticed could be causing your error:

MESSAGE_STYLE=uppercase

that should be a string

.toUppercase()

that method does not exist… rather it should be toUpperCase()

last sidepoint… are you intending to declare a global variable?

also you can try to console.log the value of what you are getting from the env file… just to check what it is…

1 Like

The filename is .env, not process.env (so just the file extension, no filename).

process.env.VARIABLE is the variable name in node that lets you access whatever is in the .env file.

1 Like

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