Debug environment variables when setting up GatsbyJS with headless Wordpress

in Uncategorised


1. Add to `gatsby-config.js`: ``` require('dotenv').config({ path: `.env.${process.env.NODE_ENV}` }); ``` https://github.com/gatsbyjs/gatsby/issues/3896#issuecomment-364058307 Most common values are development or production, so match them in the env filename 2. Create the env file: .env.development and/or .env.production https://stackoverflow.com/questions/53741674/cant-access-gatsby-environment-variables-on-the-client-side/53745249#53745249. Use the format described in https://www.gatsbyjs.com/docs/how-to/local-development/environment-variables/ ``` WPGRAPHQL_URL=https://example.com/graphql ``` 3. Debug using `console.log()`: ``` console.log({ 'process.env.NODE_ENV': process.env.NODE_ENV, 'process.env.WPGRAPHQL_URL': process.env.WPGRAPHQL_URL }); ```
#gatsbyjs