2015-05-06 45 views
0

我正在使用Node-RED并希望在Bluemix VCAP_SERVICES中进行解析,但是出现错误。我的代码是:为什么Node-RED无法解析Bluemix中的VCAP_SERVICES环境?

var services = context.global.VCAP_SERVICES; 
var env_cloudint = services['CloudIntegration'][0].credentials; 

,但我得到这个错误:

TypeError: Cannot read property 'CloudIntegration' of undefined 

我有CloudIntegration我VCAP_SERVICES。在我的代码中是否需要额外的东西来利用VCAP_SERVICES

+1

你的错误表明'服务'本身是未定义的,并不是'services'数组中的'CloudIntegration'是未定义的 –

回答

6

默认情况下,环境变量不会添加到函数全局上下文对象中。要从Node-RED流访问Bluemix VCAP_SERVICES环境变量,您需要将其添加到Function节点的全局上下文中。

编辑bluemix-settings.js并添加一个条目到functionGlobalContext属性:

functionGlobalContext: { VCAP_SERVICES: JSON.parse(process.env.VCAP_SERVICES)} 

然后重新部署应用。重新部署时,您可以在功能节点中以context.global.VCAP_SERVICES变量的形式访问VCAP_SERVICES

相关问题