From cf2af693abac1ca1a3f50175e709d432fecda91f Mon Sep 17 00:00:00 2001 From: Naomi Carrigan Date: Mon, 2 Jan 2023 09:36:34 -0800 Subject: [PATCH] feat: add note about env access location (#48866) --- .../basic-node-and-express/use-the-.env-file.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/curriculum/challenges/english/05-back-end-development-and-apis/basic-node-and-express/use-the-.env-file.md b/curriculum/challenges/english/05-back-end-development-and-apis/basic-node-and-express/use-the-.env-file.md index 80708e3fdb9..18ecaf24375 100644 --- a/curriculum/challenges/english/05-back-end-development-and-apis/basic-node-and-express/use-the-.env-file.md +++ b/curriculum/challenges/english/05-back-end-development-and-apis/basic-node-and-express/use-the-.env-file.md @@ -18,11 +18,11 @@ Let's add an environment variable as a configuration option. Create a `.env` file in the root of your project directory, and store the variable `MESSAGE_STYLE=uppercase` in it. -Then, in the `/json` GET route handler you created in the last challenge access `process.env.MESSAGE_STYLE` and transform the response object's `message` to uppercase if the variable equals `uppercase`. The response object should either be `{"message": "Hello json"}` or `{"message": "HELLO JSON"}`, depending on the `MESSAGE_STYLE` value. +Then, in the `/json` GET route handler you created in the last challenge access `process.env.MESSAGE_STYLE` and transform the response object's `message` to uppercase if the variable equals `uppercase`. The response object should either be `{"message": "Hello json"}` or `{"message": "HELLO JSON"}`, depending on the `MESSAGE_STYLE` value. Note that you must read the value of `process.env.MESSAGE_STYLE` **inside** the route handler, not outside of it, due to the way our tests run. **Note:** If you are using Replit, you cannot create a `.env` file. Instead, use the built-in SECRETS tab to add the variable. -If you are working locally, you will need the `dotenv` package. It loads environment variables from your `.env` file into `process.env`. The `dotenv` package has already been installed, and is in your project's `package.json` file. At the top of your `myApp.js` file, import and load the variables with `require('dotenv').config()`. +If you are working locally, you will need the `dotenv` package. It loads environment variables from your `.env` file into `process.env`. The `dotenv` package has already been installed, and is in your project's `package.json` file. At the top of your `myApp.js` file, add `require('dotenv').config()` to load the environment variables. # --hints--