1

I would like to use different credentials in my Netlify functions depending on my NODE_ENV variable. I have a Gatsby project and when I run netlify dev Gatsby sets NODE_ENV === development and gatsby develop command sets it to production.

Please have a look at Auth.js file https://github.com/iamskok/gatsby-dev-blog-starter/tree/feature/github-comments/.netlify/functions

Netlify functions have to use the same ENV variables as Gatsby does.

iamskok
  • 600
  • 5
  • 19

1 Answers1

1

NODE_ENV is a tricky one to use because so many web tools use it toggle on/off production optimizations - its meaning has become somewhat overloaded. Take for example deploying to Netlify you always want to see an optimised prod build, even when deploying to a non-prod develop env, so NODE_ENV should always be "production" there.

So perhaps the answer is to setup a new env var APP_ENV (or whatever) that you can freely change in Netlify/Gatsby to properly indicate the current env (dev vs. staging vs. prod) and leave NODE_ENV for the tools to manage themselves.

They talk about it a bit in the Gatsby docs here:

https://www.gatsbyjs.org/docs/environment-variables/#additional-environments-staging-test-etc

Jed Richards
  • 12,244
  • 3
  • 24
  • 35