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

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.

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.
Accepted Answer
When you use export, whether it’s in .profile, .bash_profile, or another file that’s loaded when you login to SSH, the exported data will only persist for that session (i.e. until that SSH user logs out). For data to persist, it needs to be defined in a persistent way.
Method #01
With NodeJS, the first option is to use process.env and define the environment variables in a file that isn’t accessible to the public. Yes, this is slightly frowned upon and most will say you’re doing it wrong but it’s the first obvious method.
process.env['VARIABLE_NAME'] = VALUE
Method #02
Alternatively, you can pass environment variables when running node. For example:
VAR_01='value' VAR_02='value' node app.js
Method #03
Utilize and existing package to handle .env and environment variables – particularly, dotenv.
https://github.com/motdotla/dotenv
https://www.npmjs.com/package/dotenv
Using Git/GitHub/Version Control?
Make sure you setup a line to ignore your environment files in Method #01 and #03. You don’t want to commit those files to any public repository.
When you run export, the export is only valid for the shell that you’re currently logged in to. Once you logout, whatever you’ve exported will disappear unless it’s explicity set in .bash_profile for the user in question.
For example, if you’re username is connord, you’d setup a .bash_profile for this user and add to it:
export AWS_SECRET_ACCESS_KEY=YOUR_KEY
export AWS_ACCESS_KEY_ID=YOURID
Then when you login as connord, the export commands will automatically run and you’ll be able to access those variables.
That said, export is still only valid to the logged in users’ shell, so you’d need to physically set them for persistence.
For details, you can read about process.env here:
https://nodejs.org/api/process.html#process_process_env
You’ll need to define the process.env variables for them to be persistent. For example:
process.env.AWS_SECRET_ACCESS_KEY = "YOURKEY";
process.env.AWS_ACCESS_KEY_ID = "YOURID"
You can drop the export’s in .profile, though keep in mind that this will only apply to the root user and only when that user logs in. They won’t be globally set, available to other users, or available to your application unless you’re running it while logged in via SSH. Once you close the connection to SSH, whether it’s by hitting the X or using exit, they will disappear.
The same applies even if you’re running as a user other than root (ideally, you should be – creating a sudo user and escalating to run root commands is better in terms of security).
If you need the exported data to persist, you would need to define them using process.env as noted at the end of my previous reply.