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

Read .env files in the `functions` directory #60

kentcdodds opened this issue Mar 29, 2019 · 5 comments


None yet
5 participants
Copy link

commented Mar 29, 2019

I configure env variables in the netlify UI, but locally I use .gitignored .env files and to run netlify-lambda with the right env variables.

It'd be cool if netlify-dev-plugin could solve this problem somehow :)


This comment has been minimized.

Copy link

commented Apr 1, 2019

Perhaps netlify dev could access and locally use environment variables defined in the Netlify UI, but allow any environment variables defined in a local .env file to override those found remotely.

And if this could happen automatically by using dotenv or similar internally without requiring the developer to manually include that, it would feel like a nice simplification to me.


This comment has been minimized.

Copy link

commented Apr 5, 2019

sooo.. i just found out that netlify dev ALREADY does this 🤯


and to be clear, any set process.env variables will override - but we dont read the .env file for you, you'd have to do it on your own.

if this is satisfactory to @kentcdodds, we can close this, but if anyone feels strongly that we should auto-read a .env file in the root directory, i'm open to the idea but want buyin from everyone. also have to consider conventions like which has .env.production and .env.development


This comment has been minimized.

Copy link

commented Apr 5, 2019

This is a pretty huge first step!

Handling the ability to do local overrides automatically would be a very useful utility and a benefit to using netlify dev but reasonable to have that as next iteration in my view.


This comment has been minimized.

Copy link

commented Apr 10, 2019

I'm finding that I cannot override any process.env variables when using dotenv in combination with netlify dev.

I need to check process.env.NODE_ENV to determine which callback URL to provide when authenticating users via Twitter:

const isProduction = process.env.NODE_ENV === 'production';

console.log('isProduction', isProduction);

if (!isProduction) {
  console.log('Loading dotenv config...');

// later in the file...

new TwitterStrategy({
  callbackURL: process.env.SERVER_URL + '/auth/twitter/callback'

And I can confirm that dotenv is called (via the log):

Request from ::ffff: GET /.netlify/functions/auth/twitter
isProduction false
Loading dotenv config...

When using netlify-lambda serve this works fine, but with netlify dev (after running netlify link) all the environment variables are the "production" ones, not my local .env file ones.


This comment has been minimized.

Copy link

commented Jun 10, 2019

@owenconti were you able to figure it out?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.