I'm trying to run an app with node.js functions my browser. I checked in the terminal and my javascript file which includes node.js functions runs well. However when I run the html file which is connected to the javascript file the browser returns an error which says the require function is not defined. I understand that this is because the browser can't run node.js alone
The node.js code I'm trying to run is to access a Watson visual recognition api:
var watson = require('./node_modules/watson-developer-cloud');
watson.visual_recognition({
username : '49f5d504-9387-45c6-9fda-9b58a9afc209',
password : 'IITqAn0VPaFr',
version : 'v2-beta',
version_date : '2015-12-02'
}).listClassifiers({}, function(err, response) {
if (err){
console.log(err);
} else {
console.log(JSON.stringify(response, null, 2));
}
});
I know I have all of the required files because the file runs in the terminal. Therefore I proceeded to include:
<script src ="https://cdn.socket.io/socket.io-1.4.5.js"></script>
in my index.html before connecting my javascript file.
However my javascript file still returns the same error that the require function is not defined. Am I doing something wrong? Is there any way I could run this javascript file in the browser that has node.js but specifically without using browserify (which caused me some directory problems in the past)?
require()is not built into browsers.)