人格洞察输入var nodejs

时间:2016-09-05 14:22:22

标签: node.js ibm-watson personality-insights

var express = require('express');
var app = express();
var http = require('http').Server(app);
var cfenv = require("cfenv");

var appEnv = cfenv.getAppEnv();

http.listen(appEnv.port, appEnv.bind);

var PersonalityInsightsV2 = require('watson-developer-cloud/personality-insights/v2');

var personality_insights = new PersonalityInsightsV2({
  username: '<YOUR-USERNAME>',
  password: '<YOUR-PASSWORD>'
});

personality_insights.profile({
  text: "<YOUR-100-UNIQUE-WORDS>",
  language: 'en' },
  function (err, response) {
    if (err)
      console.log('error:', err);
    else
      console.log(JSON.stringify(response, null, 2));
});

我创建了以上index.js和package.json

这两个文件
    {
  "name": "myWatsonApp",
  "version": "1.0.0",
  "description": "A Watson Personality Insights application",
  "main": "index.js",
  "scripts": {
    "start": "node index.js"
  },
  "dependencies": {
    "cfenv": "^1.0.3",
    "express": "^4.13.4",
    "watson-developer-cloud": "^2.2.0"
  }
}

当我运行npm start时,我给了我这个错误enter image description here

2 个答案:

答案 0 :(得分:0)

您的代码应该有效。

确保已安装依赖项

npm install

确保根目录中有index.js个文件,否则请更新启动脚本以指向主js文件

使用npm start

启动您的申请

答案 1 :(得分:0)

我应该将主系统中的文件包含在我运行的文件夹中。具体说明我是如何解决的!