Environment Variables
Edit this pageSolid is built on top of Vite, which offers a convenient way to handle environment variables. The following steps will show how to set up environment varaibles in a Solid project:
- In the root directory of the project, create a file called
.env
. This file will store environment variables in thekey = value
format.
Info:
To prevent accidental exposure of environment variables to the client, only variables prefixed with VITE_
will be exposed.
For example:
Only the VITE_SECRET_KEY
will be exposed to client source code, while DB_PASSWORD
will not, as shown below.
- In your Solid code, Vite will allow access to your environment variables by automatically injecting the environment variables into your application on compilation time.
For more information on environment variables in Vite and enabling TypeScript intellisense for environment variables, please refer to the Vite Documentation.