🌳 Environment Variables
Parcel uses dotenv to support loading environment variables from .env
files.
.env
files are to be stored alongside the package.json
that contains your parcel-bundler
dependency.
Parcel loads .env
files with these specific names for the following NODE_ENV
values:
valid .env filenames |
NODE_ENV=* |
NODE_ENV=test |
---|---|---|
.env |
✔️ | ✔️ |
.env.local |
✔️ | ✖️ |
.env.${NODE_ENV} |
✔️ | ✔️ |
.env.${NODE_ENV}.local |
✔️ | ✔️ |
Notably:
NODE_ENV
defaults todevelopment
..env.local
is not loaded whenNODE_ENV=test
since tests should produce the same results for everyone- Sometimes introducing a new .env file will not work immediately. Try deleting the .cache/ directory in this case.
- Accessing the
process.env
object directly is not supported, but accessing specific variables on it likeprocess.env.API_KEY
will provide the expected value. - Use the built-in
process
Node.js global, i.e. don't doimport process from "process"
, because it will not work. If you use TypeScript, you probably want to install@types/node
for it to compile.
Help us improve the docs
If something is missing or not entirely clear, please file an issue on the website repository or edit this page.