Question

Adding .env file to nodejs server

Hi, please I run my app locally and it works just fine but after deploying the app on the server, I got undefined for my environment variables. Please how can I set it up (.env files). Thanks


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.

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.

Hi @laribright8,

There are a few ways to load them up.

  • Loaded from environment variables,
  • Loaded from a JSON file on disk,

Environment variables can be access by the object process.env.NameOfVariable.
Having said that, I’ll recommend checking out the following tutorial as it will help you better understand how to call and actually work with variables in nodejs - Tutorial

If you are referring to the App Platform service of DigitalOcean, then you can check the below link which explains how to use environment variables with the App Platform

https://www.digitalocean.com/docs/app-platform/how-to/use-environment-variables/