Node server, Socket.io 'io is not defined'?

node.js, socket.io

Solution

On the client, did you do:

<script src="/socket.io/socket.io.js"></script>

before you set the `socket` variable?

Problem

I've followed the exact same steps which have always previously worked for me, create application through express, place the module dependencies in the node_modules folder. It appears that the socket.io client-side javascript file isn't being found. (I've looked at other peoples fixes, which is to include the JavaScript file in a script tab. I have not had to do this for my previous node + socket.io projects). JavaScript on client: ``` var socket = io.connect('http://localhost'); ``` JavaScript on server: ``` var io = require('socket.io').listen(app); ``` node_modules folder: ``` socket.io, which has an internal node_modules folder containing socket.io-client ``` Error Message: ``` Uncaught ReferenceError: io is not defined (anonymous function) ``` When I include the socket.io client manually: http://cdn.socket.io/stable/socket.io.js I get a different error which is: ``` Uncaught TypeError: Object #<Object> has no method 'connect' (anonymous function) ```

Original source

Related problems