Stand with Ukraine 🇺🇦
The possum is Eleventy’s mascot

Eleventy Documentation


Environment Variables #

You can set and use your own environment variables in your projects. They will be available in your code via Node.js’ process.env property.

These are typically used for setting your deployment context and private API keys. This is also the approach used to enable DEBUG mode.

Setting your own #

Via .env file #

For private keys and other sensitive information, you’ll want to create a .env file and use the dotenv package to setup those values.

Make sure you add .env to your .gitignore file. Do not commit your .env file to your repository!!

Via the command line #

Mac OS (or Linux, etc) #

MY_ENVIRONMENT=production npx @11ty/eleventy

Windows cmd.exe #

set MY_ENVIRONMENT=production & npx @11ty/eleventy

Windows Powershell (VS Code default) #

$env:MY_ENVIRONMENT="production"; npx @11ty/eleventy

Via an npm script #

You can also use the above commands in an npm script in your project’s package.json file.

Filename package.json
"scripts": {
"build:prod": "MY_ENVIRONMENT=production npx @11ty/eleventy"

Use Case Ideas #

Eleventy Supplied New in v1.0.0 #

Node.js exposes environment variables under process.env.

Eleventy also supplies its own Eleventy-specific environment variables, usually intended for more advanced use cases. You can use these in your configuration or in data files as needed.

Other pages in Using Data: