Skip to content

Commit

Permalink
docs: explain how environment variables work in production (#27189)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinszeltins committed May 14, 2024
1 parent 3fbd301 commit b90936b
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions docs/2.guide/2.directory-structure/2.env.md
Expand Up @@ -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`.

## Production Preview
## Production

**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.

Expand Down

0 comments on commit b90936b

Please sign in to comment.