简体   繁体   English

将iisnode中的Node.js环境变量(NODE_ENV)设置为生产/开发/测试

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

How do we tell iisnode to run our Node.js application environment in production/development/test? 我们如何告诉iisnode在生产/开发/测试中运行我们的Node.js应用程序环境?

We have successfully gotten our Node.js app running with iisnode but process.env.NODE_ENV is coming out as 'undefined'. 我们已成功使用iisnode运行我们的Node.js应用程序,但process.env.NODE_ENV以“未定义”形式出现。

At the moment, our web.config file is written this way: 目前,我们的web.config文件是这样编写的:

<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>

Joachim is right above that adding <iisnode node_env="production" /> to web.config allows control over the NODE_ENV value. Joachim就在上面,将<iisnode node_env="production" />到web.config允许控制NODE_ENV值。 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 . 另一种方法是在web.config旁边添加iisnode.yml文件,并在其中将NODE_ENV值node_env: productionnode_env: production See other settings you can use in iisnode.yml at https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/iisnode.yml 请参阅位于https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/iisnode.yml的 iisnode.yml中可以使用的其他设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM