- Getting Started
- Working with Templates
- Using Data
- Template Languages
- API Services
- Release History
Environment Variables #
You can set and use your own environment variables in your projects. They will be available in your code via Node.js’
These are typically used for setting your deployment context and private API keys. This is also the approach used to enable
Setting your own #
.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.
.gitignorefile. Do not commit your
.envfile 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
"build:prod": "MY_ENVIRONMENT=production npx @11ty/eleventy"
Use Case Ideas #
- Opt-in to
git Last Modifiedonly in production
- Only perform Eleventy Serverless plugin copy (via
copyEnabled) in production
- Use fewer image formats in the Image plugin to speed up local development
Node.js exposes environment variables under
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.
process.env.ELEVENTY_ROOTthe absolute path to the directory in which you’ve run the Eleventy command.
process.env.ELEVENTY_SOURCEis the method in which Eleventy has run, current either
process.env.ELEVENTY_SERVERLESSis set to
true(String) if Eleventy is running in serverless mode. If Eleventy is not running in serverless mode—due to Node forcing environment variables to be strings—this variable will not exist.