how to read System's https_proxy variable in nodejs - node.js

I know how to read environment variable from nodejs process.env.variable. I want to read system variable http_proxy which is set from windows environment variable, but process.env doesn't show http_proxy variable.
setting that environment from mycomputer->rightClick->properties ->Advensed System Seting -> Environment Variable-> new -> key :https_proxy , value : abc:80
console.log(JSON.stringify(process.env)); dosent shows https_proxy

There are several things to consider :
There are system environment variables and user environment variables. What user is the node running as? If you run it in a command window, it is probably running as your user. If you run as a service it will be the Network service user, unless you configured another user.
Is the environment variable visible for the user node is running as?
If you define a new environment variable, it is not automatically accessible everywhere. Node must be restarted to see the new variable. But this may not be sufficient. If you start node from the terminal, consider that in Windows a command window only sees the environment variables that were available when cmd was started, and those that were defined inside that terminal. That means, that you need not only to restart node, but also to close and reopen the command window.

Related

Set Environmnet Path Node.JS

I need to set environment variable for my NodeJS application. I'm using OS W10. I tried wrote in CMD
SET PORT=5000
When i wrote SET in CMD i saw value PORT=5000, but if i closed CMD and opend it one again and wrote again SET PORT i got message: Environment variable port not defined.
And if i try to get data from Node.JS application via command process.env.PORT i got value undefined. Do you have anybody experience with this isssue ?
Thanks.
An environment variable set in a Windows 10 command shell persists only for the lifetime of that command shell and is only seen in that command shell (or in child processes).
So, if you want to set an environment variable in the command shell for your node.js app, you have to set it in that very command shell that you're about to run your node.js app from. This can either be done manually or you can create a batch file that sets the environment variable and then runs your node.js program.
If you want to set a persistent environment variable that is automatically available in all future command shells, then you can go into Windows settings and modify the default environment that is passed to all new command shells. Here are some steps to do that:
Open Windows Settings
Type environment in the search box in the settings window.
If you are logged in as an administrator, you should get a drop-down that contains two options, edit system environment variables or edit environment variables for your account. Pick the desired choice.
A dialog comes up where you can then edit, add or delete persistent environment variables.
SET only sets the environment setting for current session, once closed you loose it. In order to get PORT value using process.env.PORT, you need to set PORT first then run your server within same CMD window.
If you are using BASH (Git Bash) you can do it using one line
PORT=5000 node server.js
I highly recommend using DOTENV package to manage your Environment Variables.

http proxy setting does not present in salt-minion older versions

It seems that http proxy setting in salt-minion does not support in salt-minion older version. Do we have any workaround for this.
When I am running salt command from salt-master, environment variables set in salt minion do not work.I have my http proxy setting in environment variables.but when i am running command from salt-master it does not get variables set in env.
Please let me know if any workaround for this.
Salt minion version: 0.17.5
You should set it permanently, and system wide (all users, all processes) add set variable in /etc/environment:
sudo -H gedit /etc/environment
This file only accepts variable assignments like:
HTTP_PROXY="my value"
Do not use the export keyword here.
You need to logout from current user and login again so environment variables changes take place.

Ubuntu bug? Environment variables only after logging as root

I have an IP address that I use very often, so I tried to set it as an environment variable now that I installed Ubuntu. I edited /etc/environment and added a couple of lines for my api token and my IP address. It looks like this:
PATH="some/paths"
TOKEN="my:token"
ZRUS="my.ip.address"
Now if I want to access the IP I would in theory do ssh $ZRUS. However, it does not work; I do echo $ZRUS and I get a blank line, so I do printenv and I get a list of all the environment variables and I don't see my IP there. I then do su root and I do printenv again and I get the same list plus the IP address and the TOKEN. I then do su myuser and do echo $ZRUS and magically the IP works.
Now I'm wondering why I have to log in as root first to get my global environment variables to work in the local user. It seems as if the scope varied depending on whether root has had a go on the session or not, which seems strange to me.
Do you guys think this is a bug or a functionality? And how would you overcome this?
Environment variables set in an environment file /etc/environment will only take effect if you read them into your active shell source /etc/environment or you logout/login (which will re-read the environment files into your active shell).
The act of su myuser is essentially creating a new shell for your current user which re-reads the environment file

Setting environment variables for no-login users

I have an RHEL server with tomcat installed. Tomcat runs as a no-login user called tomcat . I have set the required environment variables in /etc/profile.d/myenvvars.sh as
export JRE_HOME=/usr/lib/jvm/jre
export MY_VAR=/usr/share/mydir
The environment variables are set and can be echoed in the terminal using
# echo $MY_VAR
# sudo -u tomcat echo $MY_VAR
However when tomcat starts my environment variable is not recognised by tomcat.
As per this article I found that my environment variables will not be recognised when tomcat starts as tomcat is a no-login user. Therefore I sourced the above file in ~/.bash_profile using
. /etc/profile.d/myenvvars.sh
However, I still have the same issue, the environment variable is not reccognised.
Any help would be appreciated.
As stated in the article your linked your settings need to be in ~/.bashrc.
There may be a chance that even this is not working... depending on how your tomcat is started.
You could have a custom script for tomcat to make sure it loads the environment variables e.g. something like this
tomcat-start.sh
. /etc/profile.d/myenvvars.sh
tomcat

how do i source .bashrc remotely

I'm currently writing a script to set some PATH in a remote machine using ssh. I have successfully set the variables in the .bashrc. However, it the last step of my script is "source .bashrc". However, when i ssh to the machine manually, the PATH is still not set. What is the problem?
If on computer A, you set PATH with a script run via ssh on computer B, in a script, and then log in to computer B again, PATH will go back to what it was initially. The computer doesn't remember the value of PATH between processes, and it doesn't share it. PATH is an environment variable which is specific to each process. If you use
export PATH
then it will be inherited by child processes, but here your second login session is not a child process of the first one.

Resources