Skip to content Skip to sidebar Skip to footer

Setting Environment Variable With Nodejs

I need to set an environment variable from Node (currently using v8.9.3) Ideally, I would like to run export DATA_DIR=/var/lib/data when the program starts. 1. Tried spawning a chi

Solution 1:

You can't set an environment variable for processes that are not descendants of the current process. And under Linux, there is no such thing as system environment variable.

export is not a standalone command but a shell builtin that sets the environment variable for the current shell process and its children forked after it is set. Like you open two tabs of terminal and export a value from this tab and use the value from other tab.

You can save the key, value to file with your format then another process can read the file to get a value of the key.

Post a Comment for "Setting Environment Variable With Nodejs"