Reputation: 873
We have two completely different projects. One built with nodejs and the other using Meteor. I'm handling the Meteor project and I need a certain data from the nodejs project (Which is using socket.io). Provided that I'm not allowed to modify any of the nodejs project code, I need to communicate with it using only socket.io.
I did install the socket.io package correctly via npm and I want to fully test first if I can connect before diving into the real coding.
Here's my attempt:
var Websocket = Npm.require('socket.io');
var socket = Websocket.connect('http://10.10.10.10:80'); // Sample IP
if (Meteor.isClient) {
socket.on('message', function(res){
console.log(res);
});
Template.hello.greeting = function () {
return "Test";
};
Template.hello.events({
'click input' : function () {
// template data, if any, is available in 'this'
if (typeof console !== 'undefined')
console.log("You pressed the button");
}
});
}
Upon starting up the server, I encountered this error:
=> Your application has errors. Waiting for file change.
=> Modified -- restarting.
=> Errors prevented startup:
While building the application:
node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/sample.html:5: bad f ormatting in HTML template
node_modules/socket.io/node_modules/socket.io-client/node_modules/ws/examples/fileapi/public/index .html:1: Can't set DOCTYPE here. (Meteor sets <!DOCTYPE html> for you)
node_modules/socket.io/node_modules/socket.io-client/node_modules/ws/examples/serverstats-express_ 3/public/index.html:1: Can't set DOCTYPE here. (Meteor sets <!DOCTYPE html> for you)
node_modules/socket.io/node_modules/socket.io-client/node_modules/ws/examples/serverstats/public/i ndex.html:1: Can't set DOCTYPE here. (Meteor sets <!DOCTYPE html> for you)
node_modules/socket.io/node_modules/socket.io-client/node_modules/uglify-js/README.html:1: bad for matting in HTML template
node_modules/socket.io/node_modules/policyfile/doc/index.html:1: bad formatting in HTML template
node_modules/socket.io/node_modules/socket.io-client/node_modules/uglify-js/test/beautify.js:1:15: Unexpected token ILLEGAL
node_modules/socket.io/node_modules/socket.io-client/node_modules/uglify-js/test/testparser.js:1:1 5: Unexpected token ILLEGAL
node_modules/socket.io/node_modules/socket.io-client/node_modules/uglify-js/tmp/embed-tokens.js:1: 15: Unexpected token ILLEGAL
node_modules/socket.io/node_modules/socket.io-client/node_modules/uglify-js/tmp/test.js:1:15: Unex pected token ILLEGAL
node_modules/socket.io/node_modules/redis/diff_multi_bench_output.js:1:15: Unexpected token ILLEGA L
I can't interpret the given error. How can I fix this?
Last thing, the connection will be 2-way. I should be sending and receiving data. How can I make this work?
Upvotes: 0
Views: 1293
Reputation: 21374
It seems that you have installed the package right in your meteor project directory, i.e., you now have a node_modules directory in your meteor directory. Remember that meteor will read all subdirectories other than a few special ones (private, ..?), and will try to make the html files available as templates and load all the js files. The package you installed clearly has a lot more than the library itself, and those other files confuse meteor.
To solve this, just move your node_modules directory one up, or install the packages you need globally (npm install -g
).
Also see this: How do we or can we use node modules via npm with Meteor?
Upvotes: 1