Dotenv: Load .envrc files like direnv.

Created on 13 Dec 2015  路  5Comments  路  Source: motdotla/dotenv

Either in addition to or as a fallback in case of missing .env file, it may be nice to also check for .envrc file, e.g. from direnv, and gracefully attempt to parse & load it.

Probably relies on an implementation of #112.

All 5 comments

I'd suggest using the custom path option if you know you're looking for .envrc. It's also harmless to try to attempt to load two or more files yourself.

const dotenv = require('dotenv')
dotenv.config()
dotenv.config({ path: '.envrc' })

Thanks @maxbeatty, I'll try that.

@adjohnson916 This should work for very specific cases where you are absolutely sure that your .envrc file only includes variable assignments; however, it could easily go south if your .envrc file includes other commands which dotenv does not support.

Also, I'm just curious to hear of other people's workflow...if you are already using direnv, why use dotenv locally at all? Shouldn't direnv allow be enough?

@wilmoore I figured. Why? Might not be running the app from the current working directory, or from a different user account e.g. a system account that's not running with a shell and/or doesn't have direnv configured . Might want to use dotenv on a server to provide environment-specific configuration to the deployed application, defaulting to variables specified for local dev in .envrc via direnv.

Thanks @adjohnson916 -- good to know.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Jakobud picture Jakobud  路  3Comments

datasmurfen picture datasmurfen  路  5Comments

ffxsam picture ffxsam  路  4Comments

shai32 picture shai32  路  5Comments

AndrewChen1982 picture AndrewChen1982  路  4Comments