🌳 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_ENVdefaults todevelopment..env.localis not loaded whenNODE_ENV=testsince 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.envobject directly is not supported, but accessing specific variables on it likeprocess.env.API_KEYwill provide the expected value. - Use the built-in
processNode.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/nodefor 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.