1

I'm running a Node/Express web server on an AWS EC2 box with Ubuntu server 12.04, and I set 4 environment variables in the .bashrc file to access my database. If I run the server as a normal user, it works fine. However, if I run node as sudo, the environment variables are undefined.

Any idea why it's not working?

EmptyArsenal
  • 6,518
  • 3
  • 28
  • 51
  • 1
    possible duplicate of [How to keep Environment Variables when Using SUDO](http://stackoverflow.com/questions/8633461/how-to-keep-environment-variables-when-using-sudo) – Uri Agassi Mar 27 '14 at 14:38

1 Answers1

5

Environment variables are not passed to sudo: How to keep Environment Variables when Using SUDO

the trick is to add enviroment variables to sudoers config:

sudo visudo

add these lines

Defaults env_keep +="http_proxy"
Defaults env_keep +="https_proxy"

form ArchLinux wiki https://wiki.archlinux.org/index.php/Sudo#Environment_variables_.28Outdated.3F.29

Community
  • 1
  • 1
Uri Agassi
  • 35,245
  • 12
  • 68
  • 90