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

后端 未结 2 1357
既然无缘
既然无缘 2021-02-04 04:21

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

相关标签:
2条回答
  • 2021-02-04 05:14

    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

    0 讨论(0)
  • 2021-02-04 05:14

    For the sake of clarity the web.config file would look like this:

    <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>    
    
        <iisnode NODE_ENV="production" />            <=== Add env required here
      </system.webServer>
    </configuration> 
    
    0 讨论(0)
提交回复
热议问题