Skip to content

Commit fb23fba

Browse files
committed
feat(docs): add env docs for numbers and booleans
1 parent affc7ba commit fb23fba

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

docs/src/content/docs/getting-started/environment-vars-config.mdx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,13 @@ const _buildTimeEnv = {
6969
NEW_ENV_VAR=my-new-var
7070
```
7171

72-
4. The new environment variable is now ready to use in your project. You can access it in your code using the `Env` object, like this:
72+
4. Make sure to run `pnpm prebuild` to load the new values.
73+
74+
```bash
75+
pnpm prebuild
76+
```
77+
78+
5. The new environment variable is now ready to use in your project. You can access it in your code using the `Env` object, like this:
7379

7480
```ts title="client.ts"
7581
import { Env } from '@env';
@@ -83,7 +89,7 @@ export const client = axios.create({
8389
Using `import { Env } from '@env';` will import the env from the `src/core/env.js` file, which export client only env vars.
8490
:::
8591

86-
5. Use `APP_ENV` to load the correct `.env` file :
92+
6. Use `APP_ENV` to load the correct `.env` file :
8793

8894
```bash
8995
APP_ENV=production pnpm start -cc
@@ -98,28 +104,28 @@ As mentioned earlier, `zod` is used to validate environment variables at runtime
98104
```
99105
100106
:::note[Important]
101-
Updating `env` files will require running `pnpm prebuild` to load the new values
107+
As `dotenv` handles variables as strings, you need to convert them to the correct type while reading them from the `process.env` object. check the example below for more details on how to use numbers and boolean values.
102108
:::
103109
104110
## How it works
105111
106112
#### ✅ Validate and parse environment variables
107113
108-
If you take a look at the `env.js` file, you will notice that the file is split into tree main parts as shown below:
114+
If you take a look at the `env.js` file, you will notice that the file is split into three main parts as shown below:
109115
110116
<Code file="env.js" />
111117
112118
**In the first part** We load the correct `.env` file based on the `APP_ENV` variable using `dotenv` package. If the `APP_ENV` variable is not defined, we default to `development`.
113119
114-
we define some static variables for the app such as the app name, bundle id and package. While these variables can be added to the `.env` files, we recommend keeping them in the `env.js` file as they are not meant to change. To handle different app variants, you can add suffixes to these variables using the `withEnvSuffix` function.
120+
we define some static variables for the app such as the app name, bundle Id and package. While these variables can be added to the `.env` files, we recommend keeping them in the `env.js` file as they are not meant to change. To handle different app variants, you can add suffixes to these variables using the `withEnvSuffix` function.
115121
116122
**In the second part**, we define the `zod` schema for the environment variables.
117123
118124
We split the environment variables into two parts:
119125
120126
- **Client Variables**: Variables that are safe to be exposed to the client and used in the `src` folder.
121127
122-
- **Build Time Variables**: Variables that we don't need on the client-side and are only used in the `app.config.ts`, for example `SENTRY_AUTH` to upload the source maps to Sentry.
128+
- **Build Time Variables**: Variables that we don't need on the client-side and are only used in the `app.config.ts`, for example, `SENTRY_AUTH` to upload the source maps to Sentry.
123129
124130
These schemas are used to validate the environment variables. All the environment variables should be added to the correct schema.
125131
@@ -129,7 +135,7 @@ We use the `z.infer` utility to infer the environment variables' types from the
129135
130136
#### ✅ Use and send environment variables to the client
131137
132-
Now its easy as importing `Env` , `ClientEnv` and `withEnvSuffix` from the `./env.js` file and use inside our `app.config.ts`, and finally send client env vars to the client side using `extra` property.
138+
Now it's as easy as importing `Env` , `ClientEnv` and `withEnvSuffix` from the `./env.js` file and use inside our `app.config.ts`, and finally sending client env vars to the client side using `extra` property.
133139
134140
<Code file="app.config.ts" meta="{4,8-10}" />
135141

0 commit comments

Comments
 (0)