0

Ok so I'm basically having the same problem as this. But the answers given there don't work for me. So let me re-explain my problem. First of all, here's my code:
Server-Side Javascript (app.js)

var io = require('socket.io');
...
var sio = io.listen(app);


Client-Side Javascript (client.js)

3: var socket = (s)io.connect('http://localhost:3000');
//the (s) represents testing with and without the s out of desperateness :)

Client-Side Template (Jade)

script(src='/socket.io/socket.io.js')
script(src='/javascripts/client.js')

So from what I've read it seems like socket.io should be handling putting the socket.io.js file there but I'm guessing that I have something configured wrong because it's not doing that. Anyways the errors I get with this are:

GET http://localhost:3000/socket.io/socket.io.js 404 (Not Found)
Uncaught ReferenceError: io is not defined - client.js line 3

After doing some research it seemed that I could change the jade file to link directly to a stable file. So by changing my code to this:
Client-Side Template (Jade)

script(src='http://cdn.socket.io/stable/socket.io.js')
script(src='/javascripts/client.js')

Then the error that I get from this is:

Uncaught TypeError: Object #<Object> has no method 'connect' - client.js line 3

I've been trying to figure this out for hours now. And it seems that I need to have socket.io-client so I made sure that it is installed. I dunno if this will but I am using Express.js as well and I will give you the layout of my files.
/project

app.js  /node_modules  package.json  /public  /routes  /views

/project/node_modules

/connect  /express  /jade  /jquery  /socket.io  /stylus

/project/node_modules/socket.io

/benchmarks  index.js  Makefile       package.json  restrict_jsonp.patch
History.md   /lib      /node_modules  Readme.md

/project/node_modules/socket.io/node_modules

/policyfile  /redis  /socket.io-client

/project/public

/images  /javascripts  /jquery  /stylesheets

/project/public/javascripts

client.js

Anyways, any help would be greatly appreciated! :)

Community
  • 1
  • 1
Aust
  • 11,552
  • 13
  • 44
  • 74
  • What version of Express are you using? If 3.0, see if [socket.io.js not found](http://stackoverflow.com/questions/10191048/socket-io-js-not-found/10192084#10192084) is of any use. – Felix Loether Jul 28 '12 at 20:42

1 Answers1

1

As Felix Loether pointed out, the API for Express changed from 2.* to 3.* After spending way too many hours trying to figure out the best way to re-work my code I decided to re-install express to an earlier version by doing this:

npm install express@2.5.8 -g

There is a lot more support (as of today) for Express 2.* so as I am still learning it's better for me to use the earlier version.

Aust
  • 11,552
  • 13
  • 44
  • 74
  • After searching for quite a while this ended up being the best solution. I had to run sudo npm install a second time to get node to use the older version of express. – binarygiant Jan 17 '13 at 03:01