Hi there,
I have checked all the post about the .env file challenge and nothing seems to work. Can anyone giv eme a hint about how to solve this?
My code:
app.get("/json", function (req, res) {
if (process.env.MESSAGE_STYLE === 'uppercase') {
res.json({
"message": "HELLO JSON"
});
}
res.json({
"message": "Hello json"
});
});
When MESSAGE_STYLE is set to uppercase:
When MESSAGE_STYLE is set to uppercas:
When I click on “I’ve completed this challenge” it triggers the following error:
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 ar
npm start
> fcc-learn-node-with-express@0.1.0 start /home/runner/boilerplate-express-1
> node server.js
Node is listening on port 3000...
*
GET / - ::ffff:172.18.0.1
*
GET /style.css - ::ffff:172.18.0.1
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-04T19_41_21_595Z-debug.log
exit status 1