I set an environment variable in Digitalocean with token, but I don't understand how to use it in the code. I scrolled through the docs, but didn't get anything. Can you please tell which path I should write or anything else what I should do?
How to get Digitalocean environment variable?
1k views Asked by jaba At
2
There are 2 answers
0

To use variables in Digital Ocean using Functions over nginx runtime:
- Require dotenv into main function
- Process env into a const
- Now you can use the environment variable
EXAMPLE
function main(event, context) {
require('dotenv').config();
const SECRET = process.env.VARIABLE_NAME;
}
Remember, is necessary to register the variable before access and use it.
I would suggest using an environment function in your language of choice that searches the .env file or current global env and pull the variable that is available.
Example: for R, I can use
Sys.getenv("MY_SECRET")
to pull the variable from DO.