Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在node.js中使用bluemix.getServiceCreds()函数的正确方法是什么?_Node.js_Ibm Cloud_Demo_Ibm Watson - Fatal编程技术网

在node.js中使用bluemix.getServiceCreds()函数的正确方法是什么?

在node.js中使用bluemix.getServiceCreds()函数的正确方法是什么?,node.js,ibm-cloud,demo,ibm-watson,Node.js,Ibm Cloud,Demo,Ibm Watson,我从Bluemix克隆了Concept Insights演示,并对使用我自己的语料库做了一些小改动。它在本地运行正常,但当我将其部署到Bluemix时,当它试图访问我的语料库时,我会收到一个授权错误。我确信该错误是由于app.js中提前调用了bluemix.getServiceCreds('concept\u insights'),这显然将我的服务凭据替换为必须存储在bluemix环境中的一些凭据 有人能解释一下这个函数的目的,以及我想做什么的正确方法吗?我可能只是删除了对该函数的调用,但如果我

我从Bluemix克隆了Concept Insights演示,并对使用我自己的语料库做了一些小改动。它在本地运行正常,但当我将其部署到Bluemix时,当它试图访问我的语料库时,我会收到一个授权错误。我确信该错误是由于app.js中提前调用了bluemix.getServiceCreds('concept\u insights'),这显然将我的服务凭据替换为必须存储在bluemix环境中的一些凭据


有人能解释一下这个函数的目的,以及我想做什么的正确方法吗?我可能只是删除了对该函数的调用,但如果我这样做的话,恐怕我可能会遗漏更大的部分。这是一种将我的凭据排除在代码库之外的方法吗?如果是这样,我如何使其工作?

从bluemix创建的
VCAP\u SERVICES
变量获取
concept\u insights
服务凭据。(见)
您可能希望使用环境中的凭据,而不是在
app.js
文件中对其进行硬编码

当您的应用程序在本地运行时,您可以在
app.js
中硬编码凭据,但当它在Bluemix中运行时,这些凭据将被覆盖。如果不希望发生这种情况,请删除
bluemix.getServiceCreds('concept\u insights')

var凭证={
网址:'https://gateway.watsonplatform.net/concept-insights/api',
用户名:“”,
密码:“”,
版本:'v2'
};
创建服务时,请确保使用
标准计划。

如果您使用
Beta
计划,则必须使用
https://gateway.watsonplatform.net/concept-insights/api
as
url

var credentials = {
  url: 'https://gateway.watsonplatform.net/concept-insights/api',
  username: '<username>',
  password: '<password>',
  version: 'v2'
};