mahi
mahi

Reputation: 11

How can i read Operarting System Environment variable in nodejs

I have set path variable in Operating system . I want to access same in node js How can I access it ? I know we can access node environment variable by using process.env("variablename") and we can read from .env file using dotenv . Suppose I have set $TEST_PATH = Home/test/ I want value of $TEST_PATH in nodejs.

Upvotes: 1

Views: 3303

Answers (1)

janwvjaar
janwvjaar

Reputation: 46

When your Node.js process loads, it brings a copy of all the environment variables into context, as an object, for you to access in process.env.

So therefor you should be able to access your variable with process.env.$TEST_PATH.

For more information, you can have a futher read here

Upvotes: 1

Related Questions