What language is a .env file written in?

Viewed 21483

By convention, what language or syntax is a .env file written in?

Is it a sh script, a bash script, JavaScript, or is it a stripped down no-frills syntax inspired by sh syntax? Are all variables defined strings, or are other variable types supported?

I recently started using .env files in my NodeJS applications, but I can find nowhere in the documentation what language it is in or what constraints on syntax I must follow. I found a definition in the docker docs which seems to suggest MY_VAR=my val is the only notable feature, per se.

EDIT:

While I encountered this in the context of NodeJS, the question is not specific to nodeJS. .env files used in other contexts should be considered.

2 Answers

Here are the rules, copy-pasted from link above. Feel free to update anytime ("Commnity wiki").


Rules

The parsing engine currently supports the following rules:

  • BASIC=basic becomes {BASIC: 'basic'}

  • empty lines are skipped

  • lines beginning with # are treated as comments

  • empty values become empty strings (EMPTY= becomes {EMPTY: ''})

  • inner quotes are maintained (think JSON) (JSON={"foo": "bar"} becomes {JSON:"{\"foo\": \"bar\"}")

  • whitespace is removed from both ends of unquoted values (see more on trim) (FOO= some value becomes {FOO: 'some value'})

  • single and double quoted values are escaped (SINGLE_QUOTE='quoted' becomes {SINGLE_QUOTE: "quoted"})

  • single and double quoted values maintain whitespace from both ends (FOO=" some value " becomes {FOO: ' some value '})

  • double quoted values expand new lines, MULTILINE="new\nline" becomes

    {MULTILINE: 'new
    line'}
    
Related