Headers Error in .env Challenge

I am getting this error message “[ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client” while trying to submit .
link to my code : https://repl.it/join/vfobwjpv-moshudlanre
what could be wrong please?

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

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

console.log("Hello World");

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".toUpperCase()});
  }else {
    res.json({"message": "Hello json"});
1 Like

Hello Moshud.

I moved your post into its own topic, and formatted your code.

After a lot of testing, I cannot figure out why that error appears. Something to note: Someone else tried your code, and they were able to pass with it without the error.

The associated code which runs the tests is here:

I might spend more time later going through again. Otherwise, your code is correct, and you are welcome to skip that challenge. I hope you get this sorted.

1 Like

kindly help figure out what could e wrong with my code , i am getting an error message of header sent. “[ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client”

here is the link to my code : https://repl.it/join/vfobwjpv-moshudlanre

Alright, i will skip it but will still be hoping for a solution .



that is my env file

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”));

var response = “Hello Json”.toUpperCase();

if (process.env.MESSAGE_STYLE == “uppercase”) {
response = “Hello Json”.toUpperCase();
} else {
response = “Hello Json”;

app.get("/json", (req, res) => {
message: response

that is myapp file

I am still not passing and am confused at why. I think it is because i don’t fully understand the env file.

you need the logic for the message in the get callback