0

I created an Ubuntu micro instance on AWS, installed node and everything. I have some API credentials in my node.js app, that I'd like to store in environment variables. I'm not Linux savy, so I googled and found that best way to store these variables permanently is to edit etc/environment. I did so, and this is how it looks:

NO_OF_DAYS=30
REFRESH_INTERVAL_MINS=30
API_PASSWORD="**pppp!!"
API_USERNAME="johnny88!"

I rebooted system after this change, as I read it is needed.

Yet when I try to access these variables in my node.js app, with i.e. process.env.API_PASSWORD or process.env.NO_OF_DAYS, it just returns undefined as a value. What am I doing wrong here?

8
  • @shellter: /etc/environment is not a shell script, it only contain variable definition that will be set system wide. export won't work.
    – Cyrbil
    Commented Jan 5, 2016 at 14:42
  • 1
    @kecman: '/etc/environment' does not allows quoting, put the value as it: API_USERNAME=toto
    – Cyrbil
    Commented Jan 5, 2016 at 14:43
  • @Cyrbil : Thanks for sharing, (obviously) I didn't know that ;-) Good luck to all.
    – shellter
    Commented Jan 5, 2016 at 14:44
  • I deleted other entries and left only NO_OF_DAYS and REFRESH_INTERVAL_MINS, rebooted Ubuntu, and I still get undefined as a value of process.env.NO_OF_DAYS. And there was already an entry with quotes, some PATH=".....", so it should work with quotes?
    – kecman
    Commented Jan 5, 2016 at 15:09
  • 1
    Possible duplicate of Node Server on Ubuntu can't access environment variables as sudo
    – Andrew
    Commented Jul 24, 2018 at 23:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.