Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Node.js Environment Variable (NODE_ENV) in iisnode to Production/Development/Test

Tags:

node.js

iis

How do we tell iisnode to run our Node.js application environment in production/development/test?

We have successfully gotten our Node.js app running with iisnode but process.env.NODE_ENV is coming out as 'undefined'.

At the moment, our web.config file is written this way:

<configuration>
  <system.webServer>

    <handlers>
      <add name="iisnode" path="app.js" verb="*" modules="iisnode" />
    </handlers>

    <rewrite>
      <rules>
        <rule name="app">
          <match url="/*" />
          <action type="Rewrite" url="app.js" />
        </rule>
      </rules>
    </rewrite>

    <security>
      <requestFiltering>
        <hiddenSegments>
          <add segment="node_modules" />
        </hiddenSegments>
      </requestFiltering>
    </security>    

  </system.webServer>
  <appSettings>
    <add key="NODE_ENV" value="production" />
  </appSettings>
</configuration>
like image 838
Jon Saw Avatar asked Oct 21 '13 05:10

Jon Saw


People also ask

How do you set environment as production in node JS?

You can signal Node. js that you are running in production by setting the NODE_ENV=production environment variable. in the shell, but it's better to put it in your shell configuration file (e.g. . bash_profile with the Bash shell) because otherwise the setting does not persist in case of a system restart.

How do you print the value of an environment variable NODE_ENV in node JS?

Use echo $NODE_ENV . The command line is a shell, probably bash and that's the bash syntax to print the value of an environment variable.

What is process env NODE_ENV === development?

NODE_ENV is an environment variable that stands for node environment in express server. The NODE_ENV environment variable specifies the environment in which an application is running (usually, development or production).


1 Answers

Joachim is right above that adding <iisnode node_env="production" /> to web.config allows control over the NODE_ENV value. Another way is to add the iisnode.yml file next to your web.config, and in there spcify the NODE_ENV value as node_env: production. See other settings you can use in iisnode.yml at https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/iisnode.yml

like image 185
Tomasz Janczuk Avatar answered Sep 18 '22 15:09

Tomasz Janczuk