Installation of socket.io package on Windows 7 x64 bit environment over Express 3.x gives me very hard time.
I had to sort out tens or compilation errors and I had to install the following Windows 7 package for the installation process output no error:
(Visual Studio compiler gives me a warning C4267 (see bellow))
Despite of that correct installation I still have client side error:
Error: io is not defined
var socket = io.connect('/');
I followed the recommendation for socket.io.js to be served by nodejs server with app.js:
var express = require('express')
, http = require('http');
var app = express();
var server = http.createServer(app);
var io = require('socket.io').listen(server);
Client side decalaration in jade file is :
script(src='/socket.io/socket.io.js')
And my client script section for socket.io is :
var socket = io.connect('/');
socket.io is installed into the node-login directory which is where are located my app/public and app/server directories.
socket.io installation log:
D:\dev\node-login>npm install socket.io
npm http GET https://registry.npmjs.org/socket.io
npm http 304 https://registry.npmjs.org/socket.io
npm http GET https://registry.npmjs.org/socket.io-client/0.9.11
npm http GET https://registry.npmjs.org/policyfile/0.0.4
npm http GET https://registry.npmjs.org/base64id/0.1.0
npm http GET https://registry.npmjs.org/redis/0.7.3
npm http 304 https://registry.npmjs.org/socket.io-client/0.9.11
npm http 304 https://registry.npmjs.org/base64id/0.1.0
npm http 304 https://registry.npmjs.org/policyfile/0.0.4
npm http 304 https://registry.npmjs.org/redis/0.7.3
npm http GET https://registry.npmjs.org/uglify-js/1.2.5
npm http GET https://registry.npmjs.org/ws
npm http GET https://registry.npmjs.org/xmlhttprequest/1.4.2
npm http GET https://registry.npmjs.org/active-x-obfuscator/0.0.1
npm http 304 https://registry.npmjs.org/active-x-obfuscator/0.0.1
npm http 304 https://registry.npmjs.org/uglify-js/1.2.5
npm http 304 https://registry.npmjs.org/xmlhttprequest/1.4.2
npm http 304 https://registry.npmjs.org/ws
npm http GET https://registry.npmjs.org/zeparser/0.0.5
npm http GET https://registry.npmjs.org/commander
npm http GET https://registry.npmjs.org/options
npm http 304 https://registry.npmjs.org/zeparser/0.0.5
npm http 304 https://registry.npmjs.org/commander
npm http 304 https://registry.npmjs.org/options
> ws@0.4.25 install D:\dev\node-login\node_modules\socket.io\node_modules\socket
.io-client\node_modules\ws
> (node-gyp rebuild 2> builderror.log) || (exit 0)
D:\dev\node-login\node_modules\socket.io\node_modules\socket.io-client\node_modu
les\ws>node "C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\no
de_modules\node-gyp\bin\node-gyp.js" rebuild
bufferutil.cc
..\src\bufferutil.cc(55): warning C4267: 'initializing' : conversion from 'size
_t' to 'unsigned int', possible loss of data [D:\dev\node-login\node_modules\so
cket.io\node_modules\socket.io-client\node_modules\ws\build\bufferutil.vcxproj]
..\src\bufferutil.cc(66): warning C4267: 'initializing' : conversion from 'size
_t' to 'unsigned int', possible loss of data [D:\dev\node-login\node_modules\so
cket.io\node_modules\socket.io-client\node_modules\ws\build\bufferutil.vcxproj]
C:\Users\Vivaldi\.node-gyp\0.8.17\deps\v8\include\v8.h(183): warning C4506: no
definition for inline function 'v8::Persistent<T> v8::Persistent<T>::New(v8::Ha
ndle<T>)' [D:\dev\node-login\node_modules\socket.io\node_modules\socket.io-clie
nt\node_modules\ws\build\bufferutil.vcxproj]
with
[
T=v8::Object
]
Creating library D:\dev\node-login\node_modules\socket.io\node_modules\soc
ket.io-client\node_modules\ws\build\Release\bufferutil.lib and object D:\dev\
node-login\node_modules\socket.io\node_modules\socket.io-client\node_modules\
ws\build\Release\bufferutil.exp
Generating code
Finished generating code
bufferutil.vcxproj -> D:\dev\node-login\node_modules\socket.io\node_modules\s
ocket.io-client\node_modules\ws\build\Release\\bufferutil.node
validation.cc
C:\Users\Vivaldi\.node-gyp\0.8.17\deps\v8\include\v8.h(183): warning C4506: no
definition for inline function 'v8::Persistent<T> v8::Persistent<T>::New(v8::Ha
ndle<T>)' [D:\dev\node-login\node_modules\socket.io\node_modules\socket.io-clie
nt\node_modules\ws\build\validation.vcxproj]
with
[
T=v8::Object
]
Creating library D:\dev\node-login\node_modules\socket.io\node_modules\soc
ket.io-client\node_modules\ws\build\Release\validation.lib and object D:\dev\
node-login\node_modules\socket.io\node_modules\socket.io-client\node_modules\
ws\build\Release\validation.exp
Generating code
Finished generating code
validation.vcxproj -> D:\dev\node-login\node_modules\socket.io\node_modules\s
ocket.io-client\node_modules\ws\build\Release\\validation.node
socket.io@0.9.13 node_modules\socket.io
+-- base64id@0.1.0
+-- policyfile@0.0.4
+-- redis@0.7.3
+-- socket.io-client@0.9.11 (xmlhttprequest@1.4.2, uglify-js@1.2.5, active-x-obf
uscator@0.0.1, ws@0.4.25)
D:\dev\node-login>
Why the client can't find socket.io.js?
Answered here: https://github.com/LearnBoost/socket.io/issues/944
Change this
var server = http.createServer(app);
into this
var server = http.createServer(app).listen( 3000 );
Also I'm really surprised that you had such a pain to install it. I agree there is more pain to install various web related things on windows then linux, but node and all packages coming with it is NOT one of those. At least I had no problems with it, simple installation and then packages management via nmp makes it as easy as it would be on linux.