0

Assuming we have the next code in the App.js,

console.log(`This is the port ${process.env.PORT}`);

Is there a way to access to the value of PORT outside the runtime process?

Cokoro R1
  • 29
  • 6

2 Answers2

1

Not directly, but you could use dotenv and read the env variables from a file. Then externally, you can read that file and get the PORT variable.

Horatiu Jeflea
  • 7,256
  • 6
  • 38
  • 67
1

Values stored in process.env are environment variables, provided by your shell. In a *nix environment you can access this outside of the application like

echo $PORT

In windows you can access the environment variable like so:

echo %PORT%

It is worth noting that process.env values are not variables, and if you change the values in the runtime, it will not persist outside of the application.

Rob Brander
  • 3,702
  • 1
  • 20
  • 33