Skip to content

Commit

Permalink
feat(site): add dotenv section
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroppy committed Jan 7, 2025
1 parent 7e94eeb commit bc29854
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .internal/site/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ export default defineConfig({
text: "Routing",
link: "/introduction/routing",
},
{
text: "Dotenv",
link: "/introduction/dotenv",
},
],
},
{
Expand Down
17 changes: 17 additions & 0 deletions .internal/site/src/introduction/dotenv.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Dotenv

Dotenv is the de facto standard, but it lacks validation, making it prone to errors. In this template, we use zod to validate the required environment variables in files like `next.config.ts`. If any required variables are missing or invalid, the application will fail to execute. This approach ensures robustness at runtime.

::: code-group

<<< ../../../../.env.sample

<<< ../../../../env.ts

:::

If you need to add new environment variables, make sure to add them to both `.env` and `.env.test`, and update the `env.ts` with the corresponding zod validation.

## Why not use .env.local?

Prisma can read the `.env` file, and the `DATABASE_URL` is a required key for migration. While Next.js prioritizes `.env.local`, splitting the dotenv files can be inefficient. Therefore, to maintain consistency with Prisma, this template uses `.env`.

0 comments on commit bc29854

Please sign in to comment.