socket.io: "io is not defined"
Hi,
I’m trying to integrate the mean stack (linnovate) with socket.io and I got this error " io is not defined". The issue is also referenced here https://github.com/linnovate/mean/issues/272.
//server.js
var server = require('http').createServer(app);
var io = require('socket.io').listen(server, {
'log level': 2
});
io.sockets.on('connection', function(socket) {
console.log('Client Connected');
}); //<<<<<< 'socket' is defined but never used (linting error)
...
server.listen(port);
//public/js/services/socket.js
angular.module('mean.socket').factory('socket', ['$rootScope', function ($rootScope) {
var socket = io.connect();
return {
... // like Brian Ford did
}
}]);
// app/views/includes/foot.html which feeds into the index.html
<script type="text/javascript" src="/socket.io/socket.io.js"></script>
<script type="text/javascript" src="/js/services/socket.js"></script>
// public/js/app.js
angular.module('mean', ['ngCookies', 'ngResource', 'ngRoute', 'ui.bootstrap', 'ui.route', 'mean.system', 'mean.articles', 'mean.socket']);
angular.module('mean.socket', []);
This is the error
Linting server.js ...ERROR
[L56:C44] W098: 'socket' is defined but never used.
io.sockets.on('connection', function(socket) {
Linting public/js/services/socket.js ...ERROR
[L4:C18] W117: 'io' is not defined.
var socket = io.connect();
I don’t know what I am missing. I have no error consoled to the browser, socket.io.js is loaded properly, socket.io starts server side but nothing works. I have tried to give specific url to io.connect(), load socket.io.js from cdn but it doesn’t change. ‘io is not defined’, what does it mean, any help, any hint greatly appreciated. Trang
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Comments: 17
You can also tell JSHint that io is a global variable. it recognizes this comment notation and won’t bother warning you that io isn’t being defined in your service (which it doesn’t need to be since it’s global) just put this before your module declaration at the top of your factory service
/* globals io */ angular.module(…
You’re a bot, no?
Why do you reply to a 7 year old thread with no meaningful reply whatsoever?