Gatsby .env variables

Veröffentlicht am: 13. März 2020

Lesedauer: 1 Min.

Kategorien:
// gatsby-config.js

require("dotenv").config({
  path: `.env.${process.env.NODE_ENV}`,
})

create 2 files in root folder

.env.development .env.production

Gatsby automatically detects in which environment the website is running. So it automatically extracts the .env variables from either the .env.development or .env.production file.

Example .env key-value-pair CONTENTFULACCESSTOKEN=yourrandomkey

Articles in related Categories