diff --git a/docs/02-app/01-building-your-application/07-configuring/03-environment-variables.mdx b/docs/02-app/01-building-your-application/07-configuring/03-environment-variables.mdx index 813aa2946ed0c..7015c00dc6c98 100644 --- a/docs/02-app/01-building-your-application/07-configuring/03-environment-variables.mdx +++ b/docs/02-app/01-building-your-application/07-configuring/03-environment-variables.mdx @@ -48,7 +48,24 @@ export async function getStaticProps() { -This loads `process.env.DB_HOST`, `process.env.DB_USER`, and `process.env.DB_PASS` into the Node.js environment automatically allowing you to use them in [Route Handlers](/docs/app/building-your-application/routing/route-handlers). +> **Note**: Next.js also supports multiline variables inside of your `.env*` files: +> +> ```bash +> # .env.local +> +> # you can write with line breaks +> PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY----- +> ... +> Kh9NV... +> ... +> -----END DSA PRIVATE KEY-----" +> +> # or with `\n` inside double quotes +> PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----\nKh9NV...\n-----END DSA PRIVATE KEY-----\n" +> ``` + +> **Note**: If you are using a `/src` folder, please note that Next.js will load the .env files **only** from the parent folder and **not** from the `/src` folder. +> This loads `process.env.DB_HOST`, `process.env.DB_USER`, and `process.env.DB_PASS` into the Node.js environment automatically allowing you to use them in [Route Handlers](/docs/app/building-your-application/routing/route-handlers). For example: @@ -180,3 +197,9 @@ For example, if `NODE_ENV` is `development` and you define a variable in both `. - If you are using a [`/src` directory](/docs/app/building-your-application/configuring/src-directory), `.env.*` files should remain in the root of your project. - If the environment variable `NODE_ENV` is unassigned, Next.js automatically assigns `development` when running the `next dev` command, or `production` for all other commands. + +## Version History + +| Version | Changes | +| -------- | --------------------------------------------- | +| `v9.4.0` | Support `.env` and `NEXT_PUBLIC_` introduced. | diff --git a/packages/next-env/package.json b/packages/next-env/package.json index 0b04352dd5b9c..ad26bc207935b 100644 --- a/packages/next-env/package.json +++ b/packages/next-env/package.json @@ -30,7 +30,7 @@ }, "devDependencies": { "@vercel/ncc": "0.34.0", - "dotenv": "10.0.0", - "dotenv-expand": "8.0.1" + "dotenv": "16.3.1", + "dotenv-expand": "10.0.0" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 49c3eb6c245f8..d556b7b487bee 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1470,11 +1470,11 @@ importers: specifier: 0.34.0 version: 0.34.0 dotenv: + specifier: 16.3.1 + version: 16.3.1 + dotenv-expand: specifier: 10.0.0 version: 10.0.0 - dotenv-expand: - specifier: 8.0.1 - version: 8.0.1 packages/next-mdx: dependencies: @@ -10792,14 +10792,20 @@ packages: is-obj: 2.0.0 dev: true - /dotenv-expand@8.0.1: - resolution: {integrity: sha512-j/Ih7bIERDR5PzI89Zu8ayd3tXZ6E3dbY0ljQ9Db0K87qBO8zdLsi2dIvDHMWtjC3Yxb8XixOTHAtia0fDHRpg==} + /dotenv-expand@10.0.0: + resolution: {integrity: sha512-GopVGCpVS1UKH75VKHGuQFqS1Gusej0z4FyQkPdwjil2gNIv+LNsqBlboOzpJFZKVT95GkCyWJbBSdFEFUWI2A==} engines: {node: '>=12'} dev: true /dotenv@10.0.0: resolution: {integrity: sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==} engines: {node: '>=10'} + dev: false + + /dotenv@16.3.1: + resolution: {integrity: sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ==} + engines: {node: '>=12'} + dev: true /downsample-lttb@0.0.1: resolution: {integrity: sha512-Olebo5gyh44OAXTd2BKdcbN5VaZOIKFzoeo9JUFwxDlGt6Sd8fUo6SKaLcafy8aP2UrsKmWDpsscsFEghMjeZA==}