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

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

personality_insights.profile({
  text: '<?php echo $_Session['description'];?>',
  language: 'en' },
  function (err, response) {
    if (err)
      console.log('error:', err);
    else
      console.log(JSON.stringify(response, null, 2));
});

It doesn't display anything. I have also done npm watson cloud and saved it, I have put my credentials and also forked it on git. What am I missing? I am a beginner but would love to use this on my page!

SurvivalMachine
  • 7,946
  • 15
  • 57
  • 87
  • The code you provided us looks like it was taken from https://www.npmjs.com/package/watson-developer-cloud#personality-insights I just ran your code locally and it works for me. Are you getting no error messages? Make sure the text field contains at least 100 unique words. – Andrew Lohr Sep 03 '16 at 19:54
  • @Andrew yes there is where i took it. can you please help me,how did you set it up to run locally.I have tried to install npm bluemix,added my credentials what else do you need to run it.I am just a begginer in nodejs and I would love to know how to run it in my webpage for my master theisis.please write thbe steps wich I should follow.I have followed those in github but cant do it. –  Sep 04 '16 at 09:58

1 Answers1

1

Here are the steps to run it locally, since you are a beginner I'll start from the beginning.

Create a new folder and name it whatever you want. Put these files in there.

Name the first file: index.js

fill in <YOUR-USERNAME>, <YOUR-PASSWORD>, and <YOUR-100-UNIQUE-WORDS> variables.

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));
});

Create another file and name it: package.json

put these contents in there

{
  "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"
  }
}

open your terminal and cd to the root of your folder you just created.

Run the command: npm install

Then run the command npm start

Your application will then be running and you will see output from the personality insights call you made in index.js

Andrew Lohr
  • 5,380
  • 1
  • 26
  • 38
  • @VladimirP put additional information in this comment thread, or edit into your original post (do not post that as another answer). As for your errors are you going to your application root directory and running `npm start`? Do you have the file I wrote above and have it named `index.js`?Not sure why you are running `npm owner ls` that will just get you who can modify and publish a package to npm, which I assume you have not published your application there. – Andrew Lohr Sep 05 '16 at 15:27
  • forget about the comment above,it worked it worked.One last question how can i display it in my page just import index.js?will it give any problems in localhost? –  Sep 05 '16 at 16:41
  • By "display it on my page" I assume you mean something like displaying it on the front end in a browser. If that's what you mean then I would suggest setting up a API endpoint on your node.js server that will serve up that personality data. Then you will need a front end that will use some javascript (ajax maybe) to call that API endpoint on your server. After that you can format the data anyway you want on a html page or similar. – Andrew Lohr Sep 05 '16 at 21:58
  • Thats exatly what I am trying to do.do you have any example of this?the api endpoint isnt index,js?I just saw a tutorial on how to create a restful api but the setting of server I see it on index.js,I just a button and when clicked analyses the text that I have put into index.js –  Sep 06 '16 at 10:38
  • know that you have helped me more than enough but please help me till the end & i will never ask anything again.if you have a sample code or if you can provide me with steps I would be gratefull,this is for my master theisis –  Sep 06 '16 at 19:34
  • fortunatelly i was able to set it up for localhost,do you know how can i pass a session var to my .ejs file? –  Sep 10 '16 at 04:42