How to create environment variables?

Posted January 17, 2020 5.4k views
NginxUbuntuNode.jsDigitalOceanUbuntu 18.04

I am new to DevOps and all this. I am using an Ubuntu server to host my node.js application. Previously it was hosted in heroku. In heroku there is a special area to store environment variables, but I don’t know how to store it here. I have tried creating a variable and then exporting, but it gets flushed as the server restarts. Please, someone, help me out!

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.

2 answers

Hi @nemo011,

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


Hello, if you are referring to the App Platform service of DigitalOcean, then we request you to refer to below link, which explains about the Environment variables:

Sri Charan

Submit an Answer