question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Challenge (Use the .env File) delete the property instead of setting it to undefined

See original GitHub issue

Technically, 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.

process.env

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


Challenge: https://www.freecodecamp.org/learn/back-end-development-and-apis/basic-node-and-express/use-the--env-file

Test: https://github.com/freeCodeCamp/fcc-express-bground-pkg/blob/master/index.js

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:32 (32 by maintainers)

github_iconTop GitHub Comments

1reaction
naomi-lgbtcommented, Feb 25, 2022

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 that let 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.

0reactions
ShaunSHamiltoncommented, Mar 31, 2022

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:

If MESSAGE_STYLE is equal to the string uppercase, the response should be uppercased. For all other values (falsey or otherwise), the response should be unchanged.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found