jaba
jaba

Reputation: 82

How to get Digitalocean environment variable?

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?

Upvotes: 0

Views: 1456

Answers (2)

Jeff Monteiro
Jeff Monteiro

Reputation: 765

To use variables in Digital Ocean using Functions over nginx runtime:

  1. Require dotenv into main function
  2. Process env into a const
  3. 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.

Upvotes: 0

JJ Fantini
JJ Fantini

Reputation: 363

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.

Upvotes: 0

Related Questions