EmptyArsenal
EmptyArsenal

Reputation: 7464

Node Server on Ubuntu can't access environment variables as sudo

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?

Upvotes: 1

Views: 1057

Answers (1)

Uri Agassi
Uri Agassi

Reputation: 37409

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

Upvotes: 5

Related Questions