Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set multiple Environment variables in IISNode

I understand I can use web.config.

<iisnode      
  node_env="production"
/>

to specify one environmental node_env variable which could be accessed in server side *.js files via process.env.node_env.

However, for example I would like to have access to another environmental variable like process.env.GLOBAL_PREFIX. Similar scenarios like access to AWS credentials.

When I tried

<iisnode      
  node_env="production"
  GLOBAL_PREFIX="somevalue"
/>

, I could not get application running due to unrecognized web.config file.

like image 283
Bowei Liu Avatar asked Jan 05 '16 16:01

Bowei Liu


People also ask

How do I set multiple environment variables in Linux?

To set system-wide Linux environment variables, you can edit the /etc/environment file. Instead of appending export commands to the file, append the <NAME>='<VALUE>' pair to the end of the file.

How do I set multiple environment variables in Windows?

Press the Windows key + X to access the Power User Task Menu. In the Power User Task Menu, select the System option. Click the Advanced System Settings link in the left column. In the System Properties window, click the Advanced tab, then click the Environment Variables button near the bottom of that tab.


1 Answers

IISNode exposes any keys specified in your <appSettings> to the process.env object.

If you want to access GLOBAL_PREFIX in your Node app just do this

Web.Config

<configuration>
  <appSettings>
    <add key="GLOBAL_PREFIX" value="somevalue" />
  </appSettings>

Server.js

var globalPrefix = process.env.GLOBAL_PREFIX;
like image 54
peteb Avatar answered Nov 09 '22 06:11

peteb