Challenge (Use the .env File) delete the property instead of setting it to undefined
See original GitHub issueTechnically, if we are testing for a non-existing property we can’t set process.env.MESSAGE_STYLE
to undefined
as that is implicitly converted to a string.
Assigning a property on process.env will implicitly convert the value to a string.
This means you can’t use this logic
// process.env.MESSAGE_STYLE = 'uppercase'
let message = process.env.MESSAGE_STYLE ? {"message": "HELLO JSON"} : {"message": "Hello json"}
console.log(message) // { message: 'HELLO JSON' }
process.env.MESSAGE_STYLE = undefined;
console.log(typeof process.env.MESSAGE_STYLE) // string
message = process.env.MESSAGE_STYLE ? {"message": "HELLO JSON"} : {"message": "Hello json"}
console.log(message) // { message: 'HELLO JSON' }
But if you delete it, it works.
delete process.env.MESSAGE_STYLE
message = process.env.MESSAGE_STYLE ? {"message": "HELLO JSON"} : {"message": "Hello json"}
console.log(message) // { message: 'Hello json' }
The forum thread that made me open this issue:
https://forum.freecodecamp.org/t/use-the-end-file/498485
Test: https://github.com/freeCodeCamp/fcc-express-bground-pkg/blob/master/index.js
Issue Analytics
- State:
- Created 2 years ago
- Comments:32 (32 by maintainers)
Top Results From Across the Web
Use the .env File - Basic Node and Express - Free Code Camp
In this Basic Node and Express tutorial we use the .env file. This is the second part of four sections where we work...
Read more >react evironment variables .env return undefined
Three things to note here. the variable should be prefixed with REACT_APP_. eg: REACT_APP_WEBSITE_NAME=hello. You need to restart the server ...
Read more >.env variable is undefined and I can't seem to figure out why is ...
Its a file to store your local enviroment variables like database name, port, secrets for tokens for authentication, etc. Look up dotenv on ......
Read more >Use the .end file - JavaScript - The freeCodeCamp Forum
Challenge : Use the .env File. Link to the challenge: ... I believe the test would have to delete the property and not...
Read more >Node.js process.env Property - GeeksforGeeks
The process.env property is an inbuilt application programming interface of the process module which is used to get the user environment.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hmm, I think this warrants some further discussion.
I do agree that
process.env.MESSAGE_STYLE = undefined;
is an issue and should be fixed. However, I’m not sure thatlet message = process.env.MESSAGE_STYLE ? {"message": "HELLO JSON"} : {"message": "Hello json"}
should be considered valid logic.It seems like an anti-pattern to allow a truthiness check to pass a challenge that expects a specific value.
My suggestion is as on the comment I made on: https://github.com/freeCodeCamp/fcc-express-bground-pkg/pull/11
Nothing in the instructions here need to change. They are as clear as they need to be whereby: