From e08888ae557c68576b9de8df175805c1e235efd7 Mon Sep 17 00:00:00 2001 From: Michael Lancaster Date: Mon, 23 Mar 2020 12:09:39 +0000 Subject: [PATCH] docs(core): add env vars documentation --- CONTRIBUTING.md | 2 +- docs/map.json | 5 +++ docs/react/guides/environment-variables.md | 37 ++++++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 docs/react/guides/environment-variables.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b7e29f4e6a..dc69ef8a35 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -105,7 +105,7 @@ You can then go to `tmp/nx` (this is set up to use Nx CLI) or `tmp/angular` (thi ```bash yarn create-playground -cd tmp/nx +cd tmp/nx/proj nx g @nrwl/express:app backend nx build backend ``` diff --git a/docs/map.json b/docs/map.json index 462f819029..9ea14ef4eb 100644 --- a/docs/map.json +++ b/docs/map.json @@ -554,6 +554,11 @@ "name": "Imposing Constraints on the Dependency Graph", "id": "monorepo-tags", "file": "shared/monorepo-tags" + }, + { + "name": "Using Environment Variables", + "id": "environment-variables", + "file": "react/guides/environment-variables" } ] } diff --git a/docs/react/guides/environment-variables.md b/docs/react/guides/environment-variables.md new file mode 100644 index 0000000000..3367696cad --- /dev/null +++ b/docs/react/guides/environment-variables.md @@ -0,0 +1,37 @@ +# Environment Variables + +Environment variables are global system variables accessible by all the processes running under the Operating System (OS). Environment variables are useful to store system-wide values such as the directories to search for executable programs (PATH), OS version, Network Information, and custom variables. These env variables are passed at build time and used at the runtime of an app. + +## How to Use + +It's important to note that NX will only include in the process default and NX prefixed env vars such as: `NODE_ENV` or `NX_CUSTOM_VAR`. + +Defining environment variables can vary between OSes. It’s also important to know that this is temporary for the life of the shell session. + +**Unix systems** + +In Unix systems, we need to pass the env vars before passing the (or other) commands \ + +Let's say we want to build with development mode, with env vars we can do that like so: + +```bash +NODE_ENV=development nx build myapp +``` + +And if we want to add a custom env var for the command above, it would look like: + +```bash +NODE_ENV=development NX_BUILD_NUMBER=123 nx build myapp +``` + +**Windows (cmd.exe)** + +```bash +set "NODE_ENV=development" && nx build myapp +``` + +**Windows (Powershell)** + +```bash +($env:NODE_ENV = "development") -and (nx build myapp) +```