在Elasticbeanstalk中设置NODE_ENV变量 [英] Setting NODE_ENV variable in elasticbeanstalk
问题描述
我创建了一个名为 .elasticbeanstalk/environment.config 的文件,其中包含以下内容:
I've created a file called .elasticbeanstalk/environment.config with the following in it:
option_settings:
- option_name: NODE_ENV
value: development
我也将process.env.NODE_ENV传递给视图,以便我可以检查值
I'm also passing the process.env.NODE_ENV to the view so I can check the value
app.get('/', function(req, res) {
var data = {
env: process.env.NODE_ENV
}
res.render('upload',data);
});
在我的本地计算机上,我得到的值是"local",这是我将其设置为的值.当我通过$ git aws.push
部署到Amazons Elastic Beanstalk时,该值为空.
On my local machine I get the value "local" which is what I've set it to. When I deploy to Amazons Elastic Beanstalk via $ git aws.push
the value is empty.
EB还需要做其他事情来识别NODE_ENV设置吗?
Is there anything else I need to do for EB to recognise the NODE_ENV setting?
推荐答案
您的.config文件应位于.ebextensions
目录中,而不是.elasticbeanstalk
.
Your .config file should be located in the .ebextensions
directory, not .elasticbeanstalk
.
然后尝试一下,如果那行不通,您可以随时使用控制台.
Try it then, if that doesn't work, you can always use the console.
在此期间,您始终可以使用 Elastic Beanstalk控制台,您可以从其界面添加环境变量.为此,只需:
In the meantime, you can always use the Elastic Beanstalk Console which let's you add environment variables from its interface. To do so, just:
- 开放您的环境.
- 您会在左侧看到信息中心",配置",日志"等.单击配置链接.
- 然后点击软件配置块旁边的齿轮图标.
- 向下滚动并为环境属性"添加键/值.
- Open up your environment.
- You'll see Dashboard, Configuration, Logs and more on the left. Click the Configuration link.
- Then click the gear icon next to the Software Configuration block.
- Scroll down and add a key/value for the Environment Properties.
这篇关于在Elasticbeanstalk中设置NODE_ENV变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!