Yes, exactly this.
sample.env file is a convention many devs use to share non-secret environment variables. You cannot access the environment variables in a
sample.env file. So, you need to copy the contents of
It is bad practice to share a
.env file, so you are expected to always create one, and add it to a
.gitignore file (do not worry much about this now, if you have not heard of it - research if you want)
So, the idea is you should:
- Create a
- Copy the contents (if any) of
- Add your secret environment variables into
.env (e.g. Database URI)
- Access the variables with
process.env.VARIABLE_NAME (often, you will need to use a package like
dotenv to be able to use
Some info about using
- It is nothing more than a plain text file
- It is line-delimeted
- The above means whatever you put on one line is the
value of a variable.
So, if you say
MY_VARIABLE = VALUE; this will be the case:
console.log(process.env.MY_VARIABLE) // undefined
console.log(process.env["MY_VARIABLE "]) // " VALUE;"
// Notice the added spaces and the fact that the `value` includes the `;`
EDIT: What I mean with the above is it is a poor use of
.env variables, and the correct way is:
ANOTHER_VARIABLE=some other text
FOR_OLD_VERSIONS="some more text"
I hope this clarifies.