{"$schema":"https://doc-kit.nodejs.org/schemas/api-doc/1.0.0.json","id":"environment_variables","path":"/environment_variables","type":"module","module":"environment_variables","title":"Environment Variables","introducedIn":"v20.12.0","sourceLink":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"Environment variables are variables associated to the environment the Node.js process runs in.","summary":"Environment variables are variables associated to the environment the Node.js process runs in.","examples":[],"children":[{"kind":"section","id":"cli-environment-variables","name":"CLI Environment Variables","title":"CLI Environment Variables","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"There is a set of environment variables that can be defined to customize the behavior of Node.js,\nfor more details refer to the [CLI Environment Variables documentation](cli.html#environment-variables_1).","summary":"There is a set of environment variables that can be defined to customize the behavior of Node.js, for more details refer to the CLI Environment Variables documentation.","examples":[],"children":[]},{"kind":"property","id":"processenv","name":"env","title":"`process.env`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":null,"default":null,"description":"The basic API for interacting with environment variables is `process.env`, it consists of an object\nwith pre-populated user environment variables that can be modified and expanded.\n\nFor more details refer to the [`process.env` documentation](process.html#processenv).","summary":"The basic API for interacting with environment variables is `process.env`, it consists of an object with pre-populated user environment variables that can be modified and expanded.","examples":[],"children":[]},{"kind":"section","id":"dotenv","name":"DotEnv","title":"DotEnv","scope":"module","overloadOf":null,"stability":{"index":"2","description":"Stable"},"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"Set of utilities for dealing with additional environment variables defined in `.env` files.","summary":"Set of utilities for dealing with additional environment variables defined in `.env` files.","examples":[],"children":[{"kind":"section","id":"env-files","name":".env files","title":".env files","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"`.env` files (also known as dotenv files) are files that define environment variables,\nwhich Node.js applications can then interact with (popularized by the [dotenv](https://github.com/motdotla/dotenv) package).\n\nThe following is an example of the content of a basic `.env` file:\n\n```text\nMY_VAR_A = \"my variable A\"\nMY_VAR_B = \"my variable B\"\n```\n\nThis type of file is used in various different programming languages and platforms but there\nis no formal specification for it, therefore Node.js defines its own specification described below.\n\nA `.env` file is a file that contains key-value pairs, each pair is represented by a variable name\nfollowed by the equal sign (`=`) followed by a variable value.\n\nThe name of such files is usually `.env` or it starts with `.env` (like for example `.env.dev` where\n`dev` indicates a specific target environment). This is the recommended naming scheme but it is not\nmandatory and dotenv files can have any arbitrary file name.","summary":"`.env` files (also known as dotenv files) are files that define environment variables, which Node.js applications can then interact with (popularized by the dotenv package).","examples":[{"language":"text","displayName":null,"code":"MY_VAR_A = \"my variable A\"\nMY_VAR_B = \"my variable B\""}],"children":[{"kind":"section","id":"variable-names","name":"Variable Names","title":"Variable Names","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"A valid variable name must contain only letters (uppercase or lowercase), digits and underscores\n(`_`) and it can't begin with a digit.\n\nMore specifically a valid variable name must match the following regular expression:\n\n```text\n^[a-zA-Z_]+[a-zA-Z0-9_]*$\n```\n\nThe recommended convention is to use capital letters with underscores and digits when necessary,\nbut any variable name respecting the above definition will work just fine.\n\nFor example, the following are some valid variable names: `MY_VAR`, `MY_VAR_1`, `my_var`, `my_var_1`,\n`myVar`, `My_Var123`, while these are instead not valid: `1_VAR`, `'my-var'`, `\"my var\"`, `VAR_#1`.","summary":"A valid variable name must contain only letters (uppercase or lowercase), digits and underscores (`_`) and it can't begin with a digit.","examples":[{"language":"text","displayName":null,"code":"^[a-zA-Z_]+[a-zA-Z0-9_]*$"}],"children":[]},{"kind":"section","id":"variable-values","name":"Variable Values","title":"Variable Values","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"Variable values are comprised by any arbitrary text, which can optionally be wrapped inside\nsingle (`'`) or double (`\"`) quotes.\n\nQuoted variables can span across multiple lines, while non quoted ones are restricted to a single line.\n\nNoting that when parsed by Node.js all values are interpreted as text, meaning that any value will\nresult in a JavaScript string inside Node.js. For example the following values: `0`, `true` and\n`{ \"hello\": \"world\" }` will result in the literal strings `'0'`, `'true'` and `'{ \"hello\": \"world\" }'`\ninstead of the number zero, the boolean `true` and an object with the `hello` property respectively.\n\nExamples of valid variables:\n\n```text\nMY_SIMPLE_VAR = a simple single line variable\nMY_EQUALS_VAR = \"this variable contains an = sign!\"\nMY_HASH_VAR = 'this variable contains a # symbol!'\nMY_MULTILINE_VAR = '\nthis is a multiline variable containing\ntwo separate lines\\nSorry, I meant three lines'\n```","summary":"Variable values are comprised by any arbitrary text, which can optionally be wrapped inside single (`'`) or double (`\"`) quotes.","examples":[{"language":"text","displayName":null,"code":"MY_SIMPLE_VAR = a simple single line variable\nMY_EQUALS_VAR = \"this variable contains an = sign!\"\nMY_HASH_VAR = 'this variable contains a # symbol!'\nMY_MULTILINE_VAR = '\nthis is a multiline variable containing\ntwo separate lines\\nSorry, I meant three lines'"}],"children":[]},{"kind":"section","id":"spacing","name":"Spacing","title":"Spacing","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"Leading and trailing whitespace characters around variable keys and values are ignored unless they\nare enclosed within quotes.\n\nFor example:\n\n```text\n   MY_VAR_A   =    my variable a\n    MY_VAR_B   =    '   my variable b   '\n```\n\nwill be treated identically to:\n\n```text\nMY_VAR_A = my variable a\nMY_VAR_B = '   my variable b   '\n```","summary":"Leading and trailing whitespace characters around variable keys and values are ignored unless they are enclosed within quotes.","examples":[{"language":"text","displayName":null,"code":"   MY_VAR_A   =    my variable a\n    MY_VAR_B   =    '   my variable b   '"},{"language":"text","displayName":null,"code":"MY_VAR_A = my variable a\nMY_VAR_B = '   my variable b   '"}],"children":[]},{"kind":"section","id":"comments","name":"Comments","title":"Comments","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"Hash-tag (`#`) characters denote the beginning of a comment, meaning that the rest of the line\nwill be completely ignored.\n\nHash-tags found within quotes are however treated as any other standard character.\n\nFor example:\n\n```text\n# This is a comment\nMY_VAR = my variable # This is also a comment\nMY_VAR_A = \"# this is NOT a comment\"\n```","summary":"Hash-tag (`#`) characters denote the beginning of a comment, meaning that the rest of the line will be completely ignored.","examples":[{"language":"text","displayName":null,"code":"# This is a comment\nMY_VAR = my variable # This is also a comment\nMY_VAR_A = \"# this is NOT a comment\""}],"children":[]},{"kind":"section","id":"export-prefixes","name":"export prefixes","title":"`export` prefixes","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"The `export` keyword can optionally be added in front of variable declarations, such keyword will be completely ignored\nby all processing done on the file.\n\nThis is useful so that the file can be sourced, without modifications, in shell terminals.\n\nExample:\n\n```text\nexport MY_VAR = my variable\n```","summary":"The `export` keyword can optionally be added in front of variable declarations, such keyword will be completely ignored by all processing done on the file.","examples":[{"language":"text","displayName":null,"code":"export MY_VAR = my variable"}],"children":[]}]},{"kind":"section","id":"cli-options","name":"CLI Options","title":"CLI Options","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"`.env` files can be used to populate the `process.env` object via one the following CLI options:\n\n* [`--env-file=file`](cli.html#--env-filefile)\n\n* [`--env-file-if-exists=file`](cli.html#--env-file-if-existsfile)","summary":"`.env` files can be used to populate the `process.env` object via one the following CLI options:","examples":[],"children":[]},{"kind":"section","id":"programmatic-apis","name":"Programmatic APIs","title":"Programmatic APIs","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"There following two functions allow you to directly interact with `.env` files:\n\n* [`process.loadEnvFile`](process.html#processloadenvfilepath) loads an `.env` file and populates `process.env` with its variables\n\n* [`util.parseEnv`](util.html#utilparseenvcontent) parses the raw content of an `.env` file and returns its value in an object","summary":"There following two functions allow you to directly interact with `.env` files:","examples":[],"children":[]}]}]}