Set multiple Environment variables in IISNode
Asked Answered
A

1

10

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.

Allout answered 5/1, 2016 at 16:27 Comment(0)
T
25

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;
Tamarind answered 21/1, 2016 at 17:15 Comment(1)
Can this be added to an iisnode.yml override file and it will work?Emlyn

© 2022 - 2024 — McMap. All rights reserved.