Tests failing when the environment variable is working

Hello, I stored the variable MESSAGE_STYLE=uppercase in the .env file and to the best of my knowledge I correctly created my conditions in myApp.js. I have navigated to /json and it is correctly transforming to all caps by searching for the environment variable so I am confused as to why I am failing the tests.

Link to my code:

Your browser information:

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

Challenge: Use the .env File

Link to the challenge:

what link are you submitting?

I have tried the following:


https://boilerplate-express-1.ocheezy.repl.co/json

Hi, I’m having a similar issue to the op with this challenge.

Link to my code

I get an error/challenge failure by submitting either of the following links, even though if I browse to the '.../json' url in my browser, it works as expected with the json string being in upper case when MESSAGE_TYPE is uppercase, else lower case (Chrome Version 88.0.4324.150 (Official Build) (64-bit)):
https://boilerplate-express-1.rapscallion45.repl.co
https://boilerplate-express-1.rapscallion45.repl.co/json

This is the full output from my console, including when freeCodeCamp attempts to check my code:

 npm start

> fcc-learn-node-with-express@0.1.0 start /home/runner/boilerplate-express-1
> node server.js

Hello World
Node is listening on port 3000...
*
*
https://www.freecodecamp.org
SyntaxError: Unexpected token < in JSON at position 0
    at JSON.parse (<anonymous>)
    at /home/runner/boilerplate-express-1/node_modules/fcc-express-bground/index.js:91:26
    at IncomingMessage.<anonymous> (/home/runner/boilerplate-express-1/node_modules/fcc-express-bground/index.js:33:7)
    at IncomingMessage.emit (events.js:315:20)
    at IncomingMessage.Readable.read (_stream_readable.js:505:10)
    at flow (_stream_readable.js:1005:34)
    at resume_ (_stream_readable.js:986:3)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)
SyntaxError: Unexpected token < in JSON at position 0
    at JSON.parse (<anonymous>)
    at /home/runner/boilerplate-express-1/node_modules/fcc-express-bground/index.js:99:28
    at IncomingMessage.<anonymous> (/home/runner/boilerplate-express-1/node_modules/fcc-express-bground/index.js:33:7)
    at IncomingMessage.emit (events.js:315:20)
    at IncomingMessage.Readable.read (_stream_readable.js:505:10)
    at flow (_stream_readable.js:1005:34)
    at resume_ (_stream_readable.js:986:3)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)
_http_outgoing.js:518
    throw new ERR_HTTP_HEADERS_SENT('set');
    ^

Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
    at ServerResponse.setHeader (_http_outgoing.js:518:11)
    at ServerResponse.header (/home/runner/boilerplate-express-1/node_modules/express/lib/response.js:771:10)
    at ServerResponse.send (/home/runner/boilerplate-express-1/node_modules/express/lib/response.js:170:12)
    at ServerResponse.json (/home/runner/boilerplate-express-1/node_modules/express/lib/response.js:267:15)
    at /home/runner/boilerplate-express-1/node_modules/fcc-express-bground/index.js:108:15
    at IncomingMessage.<anonymous> (/home/runner/boilerplate-express-1/node_modules/fcc-express-bground/index.js:33:7)
    at IncomingMessage.emit (events.js:315:20)
    at IncomingMessage.Readable.read (_stream_readable.js:505:10)
    at flow (_stream_readable.js:1005:34)
    at resume_ (_stream_readable.js:986:3) {
  code: 'ERR_HTTP_HEADERS_SENT'
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! fcc-learn-node-with-express@0.1.0 start: `node server.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the fcc-learn-node-with-express@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/runner/.npm/_logs/2021-02-12T11_19_26_884Z-debug.log
 exit status 1

I’m confused as to why this error is happening?

1 Like

I have exactly the same error. I suspect because of the

SyntaxError: Unexpected token < in JSON at position 0
    at JSON.parse (<anonymous>)

There is some part of the test that is getting an html string instead of a JSON.

1 Like