I made a visual recognition app using Watson api which included a node_modules file necessary to run the api call (the api call was made from api_request and it required modules in my node_modules folder. After it worked in the terminal, I installed and use browserify to build a file in my package.json like so:
"build": "browserify api_request.js -o bundle.js"
However bundle.js gave an error when a module in the node_modules folder required another module in the node_modules folder. It doesn't seem like browserify is using 'node_modules' directory when using symlink. Does anyone know how to fix this?
Starting from (v2.0.0) you can use browserify to run the watson-developer-cloud
npm module client side. You can also require individual services now.
For example, to use Tone Analyzer client side you will need a js file (e.g app.js
):
var ToneAnalyzerV3 = require('watson-developer-cloud/tone-analyzer/v3');
var toneAnalyzer = new ToneAnalyzerV3({/* credentials */});
toneAnalyzer.tone({ text: 'Greetings from Watson Developer Cloud!' },
function(err, tone) {
if (err)
console.log(err);
else
console.log(JSON.stringify(tone, null, 2));
});
Use browserify to compile the client side js:
browserify app.js -o bundle.js"
You need to have browserify installed:
npm install browserify -g
There is a migration guide if you want to move from v1.X
to v2.X