Env
Development standards for this project
env File
With the new versions of Node.js, we can use the --env-file
flag to specify an environment variables file for our project.
By starting the project with this flag in the script, the process.env
object will contain all the variables defined in the .env
file at the root of the project.
You can have two env files in your project and choose which one to use through predefined scripts.
If you have a .env.dev
file, you can run the dev:dev
script.
This is the same for all other scripts:
This way, you can have development and production environment variables.
Validating env variables
With zod, we can create a schema
for the environment variables object to validate before the project starts, thus ensuring that the information is correct and also providing Intelisense with auto-completion of the variables we have, see:
You can set the minimum number of characters, the format, whether it should be url, email, restrict values, convert to other types, see some examples below:
With this in mind, when working with more tools or libraries that require sensitive information stored in the .env
file, simply add the necessary validations to the schema
.