Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

performance impact of reading process.env.X #562

Closed
didiercolens opened this issue Sep 7, 2021 · 2 comments
Closed

performance impact of reading process.env.X #562

didiercolens opened this issue Sep 7, 2021 · 2 comments

Comments

@didiercolens
Copy link

reading environment variables from process.env is expensive and slow according to:

it looks like the behaviour is still the same in recent nodejs, should user prefer using dotenv.config().parsed.X over process.env.X in highly use code paths ?

@yauri-io
Copy link

@didiercolens one solution is convert all of your .env content into a single .js file.

For example
.env

SERVER_HOST=0.0.0.0
SERVER_PORT=3000
SECRET=ANY_SECRET_STRING

config.js

module.exports = {
    server: {
        host: process.env.SERVER_HOST,
        port: process.env.SERVER_PORT
    },
    secret: process.env.SECRET
}

Then require the config.js in any place you want to use

@motdotla
Copy link
Owner

Thank you for posting this. It is interesting. I've decided it is beyond the scope of this module though. We are trying to keep things as simple as possible.

We'd recommend to still use process.env since that works across environments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants