Skip to content

Commit b73d529

Browse files
added env vars section to various pages
1 parent e35e705 commit b73d529

4 files changed

Lines changed: 105 additions & 14 deletions

File tree

content/100-getting-started/01-quickstart-prismaPostgres.mdx

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,31 @@ At this point, you'll be redirected to the **Database** page where you will need
4444

4545
Once the green **`CONNECTED`** label appears, your database is ready to use!
4646

47-
## 2. Download example and install dependencies
47+
## 2. Configure environment variables
4848

49-
Copy the `try-prisma` command that's shown in the Console, paste it into your terminal and execute it.
49+
First, install the required dependency:
5050

51-
For reference, this is what the command looks like:
51+
```bash
52+
npm install dotenv --save-dev
53+
```
5254

53-
```terminal
54-
npx try-prisma@latest \
55-
--template databases/prisma-postgres \
56-
--name hello-prisma \
57-
--install npm
55+
Create a `.env` file in your project root (if it doesn't exist) and add your database connection string:
56+
57+
```env
58+
DATABASE_URL="your_database_url_here"
5859
```
5960

60-
Once the `try-prisma` command has terminated, navigate into the project directory:
61+
Update your `prisma.config.ts` file in your project root:
6162

62-
```terminal
63-
cd hello-prisma
63+
```ts
64+
import "dotenv/config";
65+
import { defineConfig, env } from "prisma/config";
66+
67+
export default defineConfig({
68+
datasource: {
69+
url: env("DATABASE_URL"),
70+
},
71+
});
6472
```
6573

6674
## 3. Set database connection URL

content/100-getting-started/01-quickstart-sqlite.mdx

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,34 @@ Models in the Prisma schema have two main purposes:
9393
- Represent the tables in the underlying database
9494
- Serve as foundation for the generated Prisma Client API
9595

96-
In the next section, you will map these models to database tables using Prisma Migrate.
96+
## 3. Configure environment variables
9797

98-
## 3. Run a migration to create your database tables with Prisma Migrate
98+
First, install the required dependency:
99+
100+
```bash
101+
npm install dotenv --save-dev
102+
```
103+
104+
Create a `.env` file in your project root (if it doesn't exist) and add your database connection string:
105+
106+
```env
107+
DATABASE_URL="your_database_url_here"
108+
```
109+
110+
Update your `prisma.config.ts` file in your project root:
111+
112+
```ts
113+
import "dotenv/config";
114+
import { defineConfig, env } from "prisma/config";
115+
116+
export default defineConfig({
117+
datasource: {
118+
url: env("DATABASE_URL"),
119+
},
120+
});
121+
```
122+
123+
## 4. Run a migration to create your database tables with Prisma Migrate
99124

100125
At this point, you have a Prisma schema but no database yet. Run the following command in your terminal to create the SQLite database and the `User` and `Post` tables represented by your models:
101126

content/200-orm/200-prisma-client/000-setup-and-configuration/010-generating-prisma-client.mdx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,35 @@ For improved compatibility with ECMAScript modules (ESM) and to ensure consisten
124124

125125
:::
126126

127+
## Loading environment variables
128+
129+
To load environment variables in your Prisma application, you can use the `prisma.config.ts` file along with the `env` helper from `prisma/config`. This approach provides better type safety and configuration management.
130+
131+
1. First, install the required dependency:
132+
133+
```bash
134+
npm install dotenv --save-dev
135+
```
136+
137+
2. Create a `.env` file in your project root (if it doesn't exist) and add your database connection string:
138+
139+
```env
140+
DATABASE_URL="your_database_connection_string_here"
141+
```
142+
143+
3. Update your `prisma.config.ts` file in your project root:
144+
145+
```ts
146+
import "dotenv/config";
147+
import { defineConfig, env } from "prisma/config";
148+
149+
export default defineConfig({
150+
datasource: {
151+
url: env("DATABASE_URL"),
152+
},
153+
});
154+
```
155+
127156
## The `@prisma/client` npm package
128157

129158
The `@prisma/client` npm package consists of two key parts:

content/200-orm/500-reference/325-prisma-config-reference.mdx

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,4 +597,33 @@ You can specify a custom location for your config file when running Prisma CLI c
597597

598598
```terminal
599599
prisma validate --config ./path/to/myconfig.ts
600-
```
600+
```
601+
602+
## Loading environment variables
603+
604+
To load environment variables in your Prisma application, you can use the `prisma.config.ts` file along with the `env` helper from `prisma/config`. This approach provides better type safety and configuration management.
605+
606+
1. First, install the required dependency:
607+
608+
```bash
609+
npm install dotenv --save-dev
610+
```
611+
612+
2. Create a `.env` file in your project root (if it doesn't exist) and add your database connection string:
613+
614+
```env
615+
DATABASE_URL="your_database_connection_string_here"
616+
```
617+
618+
3. Update your `prisma.config.ts` file in your project root:
619+
620+
```ts
621+
import "dotenv/config";
622+
import { defineConfig, env } from "prisma/config";
623+
624+
export default defineConfig({
625+
datasource: {
626+
url: env("DATABASE_URL"),
627+
},
628+
});
629+
```

0 commit comments

Comments
 (0)