Question

How to access App-Level Environment Variables in Serverless JavaScript Functions?

I’ve created two test environment variables in my App Platform > App-Level Environment Variables. They are TEST and TEST_ENCRYPTED.

How do I access these in JavaScript using Digital Ocean serverless functions? I thought they may be accessible using process.env, such as process.env.TEST, but that isn’t working.

I’d appreciate guidance on this. I’m following the document, How to use environment variables in app platform, but using the variables isn’t clear to me.

Thank you


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Here you have the way to access .env vars.

const dotenv = require('dotenv');
const result = dotenv.config();

const myTest = process.env.TEST;
const myTestEncrypted = process.env.TEST_ENCRYPTED

Hi there,

You should be able to achieve this with: process.env['your_env'].

Let me know how it goes!

As a side note, in case that this could help anyone in the future, I recently answered a similar question but for PHP here:

https://www.digitalocean.com/community/questions/how-to-get-environment-variables-in-a-php-serverless-function

Best,

Bobby