Ask coding questions

← Back to all posts
Why "Run" and node server.js have different results?
misterybodon (1)

I'm writing a very simple express server.

If node server.js is run, the environmental variable defined under .env prints undefined, and If I run "Run" it prints the value.

  • I don't know what command it being executed when pressing the "Run" button.
  • And whether this is the standard way to get an environment variable into play.

Any ideas guys?

Comments
hotnewtop
Coder100 (18920)

The shell is not the same as the terminal iirc, the .env file is deleted.

misterybodon (1)

@Coder100 I don't know what you mean. Run is running something else, and I dont know what command is running, that's the question.

misterybodon (1)

@Coder100 It's not that, as you can test yourself. The environment variables wont print

Coder100 (18920)

i can't run it that way, I can't access the .env file @misterybodon

misterybodon (1)

Yes, just tried incognito and find out the same. I supposed Run would be the same. Only from my account the code access the .env file. I don't know it's just very weird. Can't do much to show the problem better. @Coder100