Report this

What is the reason for this report?

Why are environment variables being removed upon DO functions update?

Posted on May 30, 2025

I have 2 namespaces - one for production and one for development. In each namespace, I maintain 3 functions. For the production namespace, I have configured the variable NODE_ENV to production. Similarly for the development namespace, I have set the NODE_ENV env variable to development. I have done so for each function. I am doing this so that I can have my code reference production and development config setting files by looking up “.env.<NODE_ENV>” files, which have been packaged with the code.

Here’s what I have observed. With every update of the function, I see that all the env variables configured, via the DO functions web interface, get deleted.

Is this normal behaviour and if so how can I fix this?

Here’s a video of the errors I am seeing - https://drive.google.com/file/d/18denEcbNG7vCECae9m-JBmzQ8kRRRp3K/view?usp=sharing



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!

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.

Hey Prashant!

Yep, I think that this is expected behavior right now.

As far as I’m aware, when you update a DigitalOcean Function using doctl, it replaces the entire function definition, including any environment variables, unless they’re part of the update.

To avoid losing them, you’ll want to define your environment variables in your project.yml or in the .do directory if you’re using doctl deploy. Something like:

functions:
  my-function:
    env:
      NODE_ENV: production

This works well for non-sensitive values like NODE_ENV. Just be careful not to hardcode any secrets or API keys into that file if you’re committing it to version control.

If you need to handle secrets, you can load them in during your deployment process instead, or manage them separately depending on your workflow.

- Bobby

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.