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)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.