doc: add environment variables specification#52735
doc: add environment variables specification#52735IlyasShabi wants to merge 1 commit intonodejs:mainfrom
Conversation
doc/api/process.md
Outdated
|
|
||
| 6. **Multiline values**: | ||
|
|
||
| * Values enclosed in double, single, or backtick quotes that span multiple |
There was a problem hiding this comment.
| * Values enclosed in double, single, or backtick quotes that span multiple | |
| * Values enclosed in quotes described above that span multiple |
There was a problem hiding this comment.
It may also make sense to mention that unlike shells " and ' behave identially. In shells typically ' doesn't interpolate anything, " allows inline interpolation and backticks execute a command in a subshell.
doc/api/process.md
Outdated
| ```cjs | ||
| const assert = require('node:assert'); | ||
| const process = require('node:process'); | ||
| assert.strictEqual(process.env.MULTI_DOUBLE_QUOTED, 'double\nquoted'); |
There was a problem hiding this comment.
You need to escape all \ characters
| assert.strictEqual(process.env.MULTI_DOUBLE_QUOTED, 'double\nquoted'); | |
| assert.strictEqual(process.env.MULTI_DOUBLE_QUOTED, 'double\\nquoted'); |
There was a problem hiding this comment.
In fact, I got the values from test files https://github.com/nodejs/node/blob/main/test/parallel/test-dotenv.js#L72
GeoffreyBooth
left a comment
There was a problem hiding this comment.
I have two general concerns with this PR:
-
This is a lot of text to introduce and then need to maintain; we’re essentially defining our own specification here. Is this specified somewhere already that we can just link to?
-
What happens when we want to add a new feature that’s not specified, like string interpolation? We just update this spec? Would that be a breaking change?
doc/api/process.md
Outdated
|
|
||
| ```bash | ||
| # COMMENTS=work | ||
| INLINE_COMMENTS=inline comments # work |
There was a problem hiding this comment.
Is the space after comments part of the value of INLINE_COMMENTS?
There was a problem hiding this comment.
@GeoffreyBooth No, we trim spaces in both the key and the value
doc/api/process.md
Outdated
| This section describes how the environment variables file parser reads a file | ||
| and sets up the environment variables in Node.js. | ||
|
|
||
| 1. **Basic parsing**: |
There was a problem hiding this comment.
The docs generally avoid bold. Rather than this being a numbered list you could make subheadings:
| 1. **Basic parsing**: | |
| #### Basic parsing |
doc/api/process.md
Outdated
| assert.strictEqual(process.env.INLINE_COMMENTS, 'inline comments'); | ||
| ``` | ||
|
|
||
| 3. **Whitespace handling**: |
There was a problem hiding this comment.
I would list this second, above comments.
doc/api/process.md
Outdated
| * Any `export` keyword before a key is ignored, allowing compatibility with | ||
| shell scripts. |
There was a problem hiding this comment.
I initially read this as saying that any lines beginning with export get ignored, not that just the export keyword alone is ignored.
| * Any `export` keyword before a key is ignored, allowing compatibility with | |
| shell scripts. | |
| * Any `export` keyword before a key is ignored, allowing compatibility with | |
| shell scripts. The line is parsed as if `export` wasn't there. |
|
@IlyasShabi are you interested in continuing on this? this is the only missing PR from making dotenv stable. |
|
@anonrig sorry for the delay I was on holidays, yes will work on it this weekend. |
|
@GeoffreyBooth AFAIK, the only documentation for parsing env files is from the dotenv package https://github.com/motdotla/dotenv For adding new features we should update this document. If the changes are breaking, we need to document them clearly. |
|
@redyetidev your comment is not really helpful or contain any actionable item. please provide direct suggestions. |
@GeoffreyBooth there is no direct specification for dotenv other than the documentation. i believe this is the first technical specification of it. i'd like to move with this specification. do you have any blockers? |
Sorry! I'll do a review instead. I didn't mean for it to come off as unhelpful. |
avivkeller
left a comment
There was a problem hiding this comment.
Tip
I'm not a core collaborator, so these are only my suggestions (and are non-blocking)
doc/api/process.md
Outdated
| loadEnvFile(); | ||
| ``` | ||
|
|
||
| ### Environment variables file parser specification |
There was a problem hiding this comment.
Maybe rename this to Environment Variable File Parsing Specification, or something similar?
IMO the same should use a -ing word
doc/api/process.md
Outdated
|
|
||
| ### Environment variables file parser specification | ||
|
|
||
| This section describes how the environment variables file parser reads a file |
There was a problem hiding this comment.
Similarly, maybe replace references to a 'environment variables file parser' to just the 'parser', as it is already noted in the title.
| #### Comments | ||
|
|
||
| * Lines starting with `#` are treated as comments and ignored. | ||
| * Inline comments (starting with `#` after a value) are ignored, and do not |
There was a problem hiding this comment.
these are not inline comments, they are just comments
"A normal" // comment
"An inline" /* comment */ "can have more values afterward"|
@anonrig IMO this PR is ready to land |
avivkeller
left a comment
There was a problem hiding this comment.
A few nitpicks, but otherwise LGTM
(I'm not a core collaborator, so this is non-blocking)
|
hey @IlyasShabi can you apply/address the reviews? |
4e13f43 to
ce0154b
Compare
avivkeller
left a comment
There was a problem hiding this comment.
I have a few notes, but as a triage member, they are non-blocking
| This section describes how environment variables file parser reads a file | ||
| and sets up the environment variables in Node.js. |
There was a problem hiding this comment.
I think this can be reworded to:
This section describes how environment variables are read and parsed from a file.
| This section describes how environment variables file parser reads a file | ||
| and sets up the environment variables in Node.js. | ||
| While `.env` files descend from shell scripts that export environment | ||
| variables, there are important distinctions in how they handle quoting, |
There was a problem hiding this comment.
IMO, instead of "they" vs "us", you can write it in way that speaks in general
| and sets up the environment variables in Node.js. | ||
| While `.env` files descend from shell scripts that export environment | ||
| variables, there are important distinctions in how they handle quoting, | ||
| spacing, and escaping values. |
There was a problem hiding this comment.
IMO, you should list these items like so:
... various ____, such as ...
|
|
||
| #### Basic parsing | ||
|
|
||
| * The parser processes input until it finds a newline, splitting each part into |
There was a problem hiding this comment.
Remember to use active sentence style, so wording like "Input data is processed ..." is preferred
|
|
||
| ```bash | ||
| # COMMENTS=work | ||
| INLINE_COMMENTS=inline comments # work |
|
|
||
| #### Empty values | ||
|
|
||
| * Variables with no value assigned (or example, a key followed by `=`) are set to |
|
|
||
| #### Empty values | ||
|
|
||
| * Variables with no value assigned (or example, a key followed by `=`) are set to |
|
|
||
| #### Quoted values | ||
|
|
||
| * Single (`'`), double (`"`), and backtick (`` ` ``) quotes are recognized. |
There was a problem hiding this comment.
I think this shouldn't be a bullet
| const assert = require('node:assert'); | ||
| const process = require('node:process'); | ||
| assert.strictEqual(process.env.EXPAND_NEWLINES, 'expand\nnew\nlines'); | ||
| assert.strictEqual(process.env.DONT_EXPAND_UNQUOTED, | ||
| 'dontexpand\\nnewlines'); | ||
| assert.strictEqual(process.env.DONT_EXPAND_SQUOTED, | ||
| 'dontexpand\\nnewlines'); |
There was a problem hiding this comment.
IMO, assertions shouldn't be used in the example, but rather just a comment explaining the item's value
|
Closing as this has been superseded by #59052 |
Following #49148
Add documentation for environment variables specifications