Skip to content

Commit 428ad92

Browse files
authored
Improve environment variables page (#2639)
* docs: add sample env file and link * Update docusaurus/docs/cms/deployment.md * Update sample-env.md * Update environment.md * Update sample-env.md * Update sample-env.md * Reformat * Add heading for easier linking * Add links to feature pages * Fix anchor link
1 parent 53e85a4 commit 428ad92

File tree

3 files changed

+64
-3
lines changed

3 files changed

+64
-3
lines changed

docusaurus/docs/cms/configurations/environment.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ tags:
88
- environment
99
---
1010

11+
import SampleEnv from '/docs/snippets/sample-env.md'
12+
1113
# Environment configuration and variables
1214

1315
Strapi provides specific environment variable names. Defining them in an environment file (e.g., `.env`) will make these variables and their values available in your code.
@@ -29,14 +31,27 @@ Strapi provides the following environment variables:
2931
| `NODE_ENV` | Type of environment where the application is running.<br/><br/>`production` enables specific behaviors (see <ExternalLink to="https://nodejs.org/en/learn/getting-started/nodejs-the-difference-between-development-and-production" text="Node.js documentation"/> for details) | `String` | `'development'` |
3032
| `BROWSER` | Open the admin panel in the browser after startup | `Boolean` | `true` |
3133
| `ENV_PATH` | Path to the file that contains your environment variables | `String` | `'./.env'` |
32-
| `STRAPI_PLUGIN_I18N_INIT_LOCALE_CODE` <br/><br/>_Optional_ | Initialization locale for the application, if the [Internationalization (i18n) plugin](/cms/features/internationalization) is installed and enabled on Content-Types (see [Configuration of i18n in production environments](/cms/features/internationalization#configuration)) | `String` | `'en'` |
34+
| `STRAPI_PLUGIN_I18N_INIT_LOCALE_CODE` <br/><br/>_Optional_ | Initialization locale for the application, if the [Internationalization (i18n) feature](/cms/features/internationalization) is installed and enabled on Content-Types (see [Configuration of i18n in production environments](/cms/features/internationalization#configuration)) | `String` | `'en'` |
3335
| `STRAPI_ENFORCE_SOURCEMAPS` | Forces the bundler to emit source-maps, which is helpful for debugging errors in the admin app. | `boolean` | `false` |
3436
| `FAST_REFRESH` | _(Only applies to webpack)_<br/>Use <ExternalLink to="https://github.com/pmmmwh/react-refresh-webpack-plugin" text="react-refresh"/> to enable "Fast Refresh" for near-instant feedback while developing the Strapi admin panel. | `boolean` | `true` |
37+
| `HOST` | Address the Strapi server listens on | `String` | `0.0.0.0` |
38+
| `PORT` | Port used by the Strapi server | `Number` | `1337` |
39+
| `APP_KEYS` | Comma-separated keys used to sign cookies and other secrets | `String` | `auto-generated` |
40+
| `API_TOKEN_SALT` | Salt used when creating [API tokens](/cms/features/api-tokens) | `String` | `auto-generated` |
41+
| `ADMIN_JWT_SECRET` | Secret for JWT tokens used in the admin panel | `String` | `auto-generated` |
42+
| `JWT_SECRET` | Secret for JWT tokens generated by the [Users & Permissions](/cms/features/users-permissions) feature | `String` | `auto-generated` |
43+
| `TRANSFER_TOKEN_SALT` | Salt used for transfer tokens by the [Data Management](/cms/features/data-management) feature | `String` | `auto-generated` |
44+
| `DATABASE_CLIENT` | Database client to use (e.g., `sqlite`) | `String` | `sqlite` |
45+
| `DATABASE_FILENAME` | Location of the SQLite database file | `String` | `.tmp/data.db` |
3546

3647
:::tip
3748
Prefixing an environment variable name with `STRAPI_ADMIN_` exposes the variable to the admin front end (e.g., `STRAPI_ADMIN_MY_PLUGIN_VARIABLE` is accessible through `process.env.STRAPI_ADMIN_MY_PLUGIN_VARIABLE`).
3849
:::
3950

51+
### Example `.env` file
52+
53+
<SampleEnv />
54+
4055
## Environment configurations
4156

4257
Configurations can be created with the following naming and structure conventions: `./config/env/{environment}/{filename}`. This is useful when you need specific static configurations for specific environments and using environment variables is not the best solution.
@@ -102,4 +117,4 @@ To learn deeper about how to use environment variables in your code, please refe
102117

103118
<CustomDocCardsWrapper>
104119
<CustomDocCard icon="chalkboard-simple" title="Access and cast variables" description="Learn how to access and cast environment variables with the env() utility." link="/cms/configurations/guides/access-cast-environment-variables" />
105-
</CustomDocCardsWrapper>
120+
</CustomDocCardsWrapper>

docusaurus/docs/cms/deployment.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ module.exports = ({ env }) => ({
7171
});
7272
```
7373

74-
Then you can create a `.env` file or directly set environment variables in your chosen deployment platform:
74+
Strapi generates a `.env` file with default values when you create a new project. You can edit this file or set variables in your chosen deployment platform (see [example `.env` file](/cms/configurations/environment#example-env-file)):
7575

7676
```
7777
HOST=10.0.0.1
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
The Strapi CLI generates an `.env` and an `.env.example` file when creating a new project. The files contain automatically-generated security keys and database settings similar to the following:
2+
3+
<Tabs>
4+
<TabItem value="env-example" label=".env.example">
5+
6+
```env title=".env.example"
7+
HOST=0.0.0.0
8+
PORT=1337
9+
APP_KEYS="toBeModified1,toBeModified2"
10+
API_TOKEN_SALT=tobemodified
11+
ADMIN_JWT_SECRET=tobemodified
12+
TRANSFER_TOKEN_SALT=tobemodified
13+
JWT_SECRET=tobemodified
14+
ENCRYPTION_KEY=tobemodified
15+
```
16+
17+
</TabItem>
18+
<TabItem value="env" label=".env">
19+
20+
The variables might differ depending on options selected on project creation.
21+
22+
```env title=".env"
23+
# Server
24+
HOST=0.0.0.0
25+
PORT=1337
26+
27+
# Secrets
28+
APP_KEYS=appkeyvalue1,appkeyvalue2,appkeyvalue3,appkeyvalue4
29+
API_TOKEN_SALT=anapitokensalt
30+
ADMIN_JWT_SECRET=youradminjwtsecret
31+
TRANSFER_TOKEN_SALT=transfertokensaltvalue
32+
ENCRYPTION_KEY=yourencryptionkey
33+
34+
# Database
35+
DATABASE_CLIENT=sqlite
36+
DATABASE_HOST=
37+
DATABASE_PORT=
38+
DATABASE_NAME=
39+
DATABASE_USERNAME=
40+
DATABASE_PASSWORD=
41+
DATABASE_SSL=false
42+
DATABASE_FILENAME=.tmp/data.db
43+
```
44+
45+
</TabItem>
46+
</Tabs>

0 commit comments

Comments
 (0)