{"id":829,"date":"2021-07-13T04:43:42","date_gmt":"2021-07-13T03:43:42","guid":{"rendered":"https:\/\/editjournal.redakt.eu\/faxmodem\/?p=829"},"modified":"2021-07-27T15:39:31","modified_gmt":"2021-07-27T14:39:31","slug":"debugging-environment-variables-in-gatsbyjs","status":"publish","type":"post","link":"https:\/\/editjournal.redakt.eu\/faxmodem\/blog\/uncategorised\/debugging-environment-variables-in-gatsbyjs\/","title":{"rendered":"Debug environment variables when setting up GatsbyJS with headless WordPress"},"content":{"rendered":"<p>1. Add to `gatsby-config.js`:<\/p>\n<p>```<br \/>\nrequire('dotenv').config({<br \/>\n    path: `.env.${process.env.NODE_ENV}`<br \/>\n});<br \/>\n```<\/p>\n<p>https:\/\/github.com\/gatsbyjs\/gatsby\/issues\/3896#issuecomment-364058307<br \/>\nMost common values are development or production, so match them in the env filename<\/p>\n<p>2. Create the env file: .env.development and\/or .env.production<br \/>\nhttps:\/\/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\/<br \/>\n```<br \/>\nWPGRAPHQL_URL=https:\/\/example.com\/graphql<br \/>\n```<\/p>\n<p>3. Debug using `console.log()`:<\/p>\n<p>```<br \/>\nconsole.log({<br \/>\n    'process.env.NODE_ENV': process.env.NODE_ENV,<br \/>\n    'process.env.WPGRAPHQL_URL': process.env.WPGRAPHQL_URL<br \/>\n});<br \/>\n```<\/p>\n","protected":false},"excerpt":{"rendered":"<p>GatsbyJS talks to headless Wordpress via a GraphQL endpoint which you can specify using an environment variable. Here&#8217;s how you can debug it when setting up the connection.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[683],"class_list":["post-829","post","type-post","status-publish","format-standard","hentry","category-uncategorised","tag-gatsbyjs","entry"],"_links":{"self":[{"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/posts\/829","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/comments?post=829"}],"version-history":[{"count":16,"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/posts\/829\/revisions"}],"predecessor-version":[{"id":860,"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/posts\/829\/revisions\/860"}],"wp:attachment":[{"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/media?parent=829"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/categories?post=829"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/tags?post=829"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}