ENV Var is Undefined

I have an issue with ENV variables always returning “undefined” for any new project I create.

Interestingly, I remixed an old project of mine in which the ENV variable functioned as expected. I supplied a new variable value to the newly created, remixed project. This new Project, despite having the exact same code as the working project, returns “Undefined” when calling “process.env.myVar”.

Googling hasn’t yielded results. It suggests I install extra dependencies, such as “dotenv” - but my old project had no such dependencies, so that cannot be the issue. Unsure of how to proceed. Any tips would be greatly appreciated!

When you remix a project, the env variables don’t carry over so you need to write them again in the .env file. If this isn’t the issue, can clarify a bit more? E.g. code examples


Hi @EddiesTech - thanks for responding so quickly. I had given up for the day otherwise, and I believe your response prompted my issue resolution - although it wasn’t really what you said, unfortunately.

I am aware that the value of env variables doesn’t carry over from remixed projects. After remixing my original project, I manually copied the value from the working project into the same env variable in the remixed project. It was the same variable name, save variable content, same base code, different result.

Or so I thought. For some reason when copy/pasting into Glitch’s new env variable interface, the pasted “Variable Value” did not automatically get wrapped with quotes. I realized this only after clicking the “plaintext” button on that screen. From there I saw in the working file:

mySensitiveInfo="this works"

and in the non-working file:

mySensitiveInfo=this doesn't work

The values of the variables there were changed for demonstration purposes. I was actually working with a MongoDb URI.

Regardless, in the Environmental Variables screen, after clicking “Plaintext” I was able to wrap the value of the variable in quotes, and that fixed my issue.

Thank you for giving me the inspiration to look again.


Well, no. Here he manually reentered them despite it getting wiped and still didn’t work. As he said, the issue is that if you wrap a variable in quotes using the Glitch env UI, it works as if it were wrapped, but if you ever go back to the env UI, it doesn’t show as wrapped in quotes unless you go into the plaintext UI. For some reason, after a refresh, the UI doesn’t show the quotes you added anymore, but they are still there. @aarongilly copied from the UI, not plaintext, meaning that the quotes weren’t there when they should have been

1 Like

I’m not making myself clear enough.

Yes, the value of the variable was wiped. I am and was aware of that. The key remained, again I get that. ’

What I’m saying is that I manually copied the text content of the input box that represents the Environment Variable Value from the original project into the input box that represents the same env variable for the same key. Because I remixed the project, that key originally had no value, as you point out. I pasted a value into the input box.

However, when I clicked the “plaintext” button, I found that the value I pasted in wasn’t being wrapped in quotes.

For anyone having an issue similar to what I’ve described:
Make sure the values of your env variables are properly quote-wrapped by clicking the “plaintext” button.


Yes @aarongilly . That’s what I was trying to explain to @khalby786
The UI doesn’t show the quotes when really they are there in the plaintext.

1 Like

Sorry people, I misunderstood and misread the original post :sweat_smile:. Firstly, I quoted the wrong part of the solution post and when I read the part of the post which was originally meant to be quoted, I misread it. :grimacing:

1 Like

ah no worries. I appreciate both of your help and attention!

Just glad it’s figured out. And hopefully somebody else someday finds this post and it helps them.

Thanks again.

1 Like

Side note: Would be really nice for the graphical .env editor to properly/always quote the values.

1 Like

Also just discovered that updating the values in the .env doesn’t update them in the Terminal automatically, nor with the refresh command. The Terminal needs to be closed and reopened for them to apply.

After all, you can always switch to Plaintext mode and correctly edit it in case of a syntax error. But yes, I would like to see this feature too.