Environment Variables
#
Setting Environment VariablesEnvironment variables can be set to your Micro through the Deta cli's update command. These variables are encrypted at rest.
You need to create a file where you specify your environment variables with their values.
note
We strongly recommend creating a file called .env
so that this file is skipped by the Deta cli and not deployed with your Micro's code. Also, please do not share/commit your env file publicly.
You can use the following command to update your environment variables:
The environment variables must be defined in the following format:
You should not change the value of the environment variables through your Micro's code, as the change will not persist in following invocations of your Micro.
#
ExampleSuppose you want to make an environment variable SECRET_TOKEN
with a value of abcdefgh
accessible to your Micro's code.
- Create a
.env
file with the following content:
- Update the Micro's environment variables with the
deta update
command:
#
Pre-Set Environment VariablesDeta pre-sets some environment variables in your Micro's environment which are used by our runtime.
note
These pre-set variables are specific to your Micro and should not be shared publicly (unless we mention otherwise). These variables can not be updated from the cli.
The following pre-set environment variables could be useful for you:
- DETA_PATH
DETA_PATH
stores a unique identifier for your Micro. This value is also used as the sub-domain under which your Micro is available through http
. For example, if your DETA_PATH
variable contained a value of sdfgh
then your Micro is accessible at https://sdfgh.deta.dev.
note
This value does not store the self assigned sub-domain value at the moment.
- DETA_RUNTIME
DETA_RUNTIME
indicates if your code is running on a Micro, with a string value "true"
.
In some cases, you might need to run some code exclusively in local development and not in a Micro. For example, if you're running a FastAPI project on your Micro, and you've got an endpoint that dumps debug information like so:
If you want this endpoint to be only available locally, you can check the environment variable to selectively execute code:
- DETA_PROJECT_KEY
DETA_PROJECT_KEY
is a project key generated for your Micro for authentication with Deta Base and Deta Drive.
Each micro has its own project key and this should not be shared publicly.
While using our SDKs(the latest versions) within a Deta Micro, you can omit specifying the project key when instantiating a service instance.
- JavaScript
- Python
#
IssuesIf you run into any issues, consider reporting them in our Github Discussions.