Stuck on Use the .env file, Err: cannot send headers after they are sent to the client

I have been stuck on this challenge for hours, seemingly with the correct code from the very start. I have gone over a lot of forum posts, tried all of the different “working solutions” posted. Tests still don’t pass for me. I have tried commenting out or deleting all previous challenge code, I have tried making new’s, and only solving this challenge. No luck.

My .env file:


My code:

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

console.log("Hello World");

app.get("/", function(req, res) {
  res.sendFile(__dirname + "/views/index.html");

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

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:85.0) Gecko/20100101 Firefox/85.0.

Challenge: Use the .env File

Link to the challenge:

I figured there might be something wrong, so I skipped to the next challenge (Implement a Root-Level Request Logger Middleware), where I also was unable to pass the tests. However my console output seems to be exactly what the challenge asked for. Are several of the challenges in this section bugged? I’ve been struggling with these for hours.
I guess I should make a new post for the next challenge, but after spending hours on this after getting it right in the first five minutes, I feel like skipping the whole section is a better use of my time.

Thanks for your reply!

the next challenge has no known bug, try opening a new topic for that challenge

they are not that easy, I was struggling a fair bit when I was doing those myself

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