mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 15:15:19 +00:00
docs: explain how environment variables work in production (#27189)
This commit is contained in:
parent
3fbd301e44
commit
b90936b4f1
@ -33,11 +33,25 @@ npx nuxi dev --dotenv .env.local
|
|||||||
|
|
||||||
When updating `.env` in development mode, the Nuxt instance is automatically restarted to apply new values to the `process.env`.
|
When updating `.env` in development mode, the Nuxt instance is automatically restarted to apply new values to the `process.env`.
|
||||||
|
|
||||||
## Production Preview
|
## Production
|
||||||
|
|
||||||
**After your server is built**, you are responsible for setting environment variables when you run the server.
|
**After your server is built**, you are responsible for setting environment variables when you run the server.
|
||||||
|
|
||||||
Your `.env` file will not be read at this point. How you do this is different for every environment.
|
Your `.env` files will not be read at this point. How you do this is different for every environment.
|
||||||
|
|
||||||
|
This design decision was made to ensure compatibility across various deployment environments, some of which may not have a traditional file system available, such as serverless platforms or edge networks like Cloudflare Workers.
|
||||||
|
|
||||||
|
Since `.env` files are not used in production, you must explicitly set environment variables using the tools and methods provided by your hosting environment. Here are some common approaches:
|
||||||
|
|
||||||
|
* You can pass the environment variables as arguments using the terminal:
|
||||||
|
|
||||||
|
`$ DATABASE_HOST=mydatabaseconnectionstring node .output/server/index.mjs`
|
||||||
|
|
||||||
|
* You can set environment variables in shell configuration files like `.bashrc` or `.profile`.
|
||||||
|
|
||||||
|
* Many cloud service providers, such as Vercel, Netlify, and AWS, provide interfaces for setting environment variables via their dashboards, CLI tools or configuration files.
|
||||||
|
|
||||||
|
## Production Preview
|
||||||
|
|
||||||
For local production preview purpose, we recommend using [`nuxi preview`](/docs/api/commands/preview) since using this command, the `.env` file will be loaded into `process.env` for convenience. Note that this command requires dependencies to be installed in the package directory.
|
For local production preview purpose, we recommend using [`nuxi preview`](/docs/api/commands/preview) since using this command, the `.env` file will be loaded into `process.env` for convenience. Note that this command requires dependencies to be installed in the package directory.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user