- Get Started
- Framework
- Get Started
- Framework
6.11. Environment Variables
In this chapter, you'll learn how environment variables are loaded in Local Protocol.
System Environment Variables#
The Local Protocol application loads and uses system environment variables.
For example, if you set the PORT
environment variable to 8000
, the Local Protocol application runs on that port instead of 9000
.
In production, you should always use system environment variables that you set through your hosting provider.
Environment Variables in .env Files#
During development, it's easier to set environment variables in a .env
file in your repository.
Based on your NODE_ENV
system environment variable, which is considered as development
if not set, Local Protocol will try to load environment variables from the following .env
files:
Environment |
|
---|---|
|
|
|
|
|
|
|
|
Set Environment in loadEnv
#
In the localproto-config.ts
file of your Local Protocol application, you'll find a loadEnv
function used that accepts process.env.NODE_ENV
as a first parameter.
This function is responsible for loading the correct .env
file based on the value of process.env.NODE_ENV
.
To ensure that the correct .env
file is loaded as shown in the table above, only specify development
, production
, staging
or test
as the value of process.env.NODE_ENV
or as the parameter of loadEnv
.