Basic Node and Express - Use the .env File

Tell us what’s happening:
Hello, I am working on this challenge using replit and the secret tab. I added MESSAGE_STYLE as the key and uppercase as the value for it.
Describe your issue in detail here.
The tests do not pass and it says there is an error in syntax in line

Your code so far

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

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

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

app.get("/", (request, response) => {
  let absolutePath = __dirname + "/views/index.html";

Your browser information:

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

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

Link to the challenge:

if (process.env.MESSAGE_STYLE === “uppercase”){

SyntaxError: Invalid or unexpected token
at Object.compileFunction (node:vm:352:18)
at wrapSafe (node:internal/modules/cjs/loader:1033:15)
at Module._compile (node:internal/modules/cjs/loader:1069:27)
at Object.Module._extensions…js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object. (/home/runner/boilerplate-express-2/server.js:7:13)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
exit status 1

The error message shows you which line the syntax error is on.

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

__dirname is a variable name. You are attempting to concatenate it with something that is not a variable name or a string.

thanks a lot. It was that

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