PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, November 8, 2022

[FIXED] How to use Digitalocean's app platform component environmental variables?

 November 08, 2022     digital-ocean, javascript, node.js     No comments   

Issue

I am using Digital Ocean's app platform to host a NodeJS app. I do not understand the documentation for using environmental variables within my NodeJS code. https://www.digitalocean.com/docs/app-platform/how-to/use-environment-variables/#define-build-time-environment-variables when I try to add the environmental variable like I think the documentation wants me to I get a syntax error: mongoose.connect(${_self.DATABASE_URL}, {useNewUrlParser: true}); What is the correct usage?


Solution

Step 1:

In your App settings you should find the App-Level Environment Variables.

You could set a variable there like this:

Keys: APP_LEVEL_EXAMPLE_VAR 
Values: rafiki

Don´t forget to save.

Now you have an App-Level Environment Variable.

Step 2:

In your app´s project.yml file, you can set a variable that reads the App-Level variable like this:

environment: { 
  EXAMPLE_VAR: ${APP_LEVEL_EXAMPLE_VAR}
}

Step 3:

Now you can access the value of APP_LEVEL_EXAMPLE_VAR in your app like this:

const value = process.env.EXAMPLE_VAR


Answered By - Arnar Ingi Gunnarsson
Answer Checked By - Robin (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing