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
Answer a question...

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
Bobby Iliev
Site Moderator
Site Moderator badge
July 28, 2022

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:



Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.