I know I can pass local environment variables to 11ty by running it with a syntax like $ SECRET_TOKEN=xxxyyy npx @11ty/eleventy --serve but what's the best way to pick this up from a local .env file?
Failing that, what's a good way to inject a secret value into process.env without committing the secret to source control?
Thank you!
Take a look at https://www.npmjs.com/package/dotenv
@michrome I'm using dotenv in my project as @DirtyF suggested. You can see how it's used here:
Sample env file:
.env.sample
Data file:
_data/webmentions.js
Thank you @DirtyF and @chrisssycollins 馃 dotenv worked perfectly.
For anyone else coming to this later, it's as simple as:
dotenv with $ npm install --save-dev dotenv.require('dotenv').config(); to your .eleventy.js file.
Most helpful comment
Thank you @DirtyF and @chrisssycollins 馃
dotenvworked perfectly.For anyone else coming to this later, it's as simple as:
dotenvwith$ npm install --save-dev dotenv.require('dotenv').config();to your.eleventy.jsfile.