can't get it to work



Ok, problem with the server solved. This is the full server code integrated into my project.

var http =              require('http');
var express =           require('express');
var requestHandler =    require(__dirname + '/app_modules/request-handler.js');
var app =               express();

    app.use(express.static(__dirname + '/html'));

var httpServer = http.createServer(app);

var io = require('').listen(httpServer);

io.on('connection', function(socket){
    socket.on('event', function(data){

    socket.on('disconnect', function(){


The next issue is including the source .js in my static html page. This throws an error:

<script src="/"></script>

Resource interpreted as Script but transferred with MIME type text/plain: "http://localhost/". localhost/:206
Uncaught SyntaxError: Unexpected identifier
Uncaught ReferenceError: io is not defined 


I'm trying to get this sucker working on a test server. This is 1:1, straight from the docs on github.

var app = require('express')();
var server = require('http').Server(app);
var io = require('')(server);

io.on('connection', function(socket){
    socket.on('event', function(data){

    socket.on('disconnect', function(){



Here is what I'm getting:

[INFO] 19:37:40 Restarting
[ERROR] 19:37:40 TypeError
TypeError: object is not a function
    at Object.<anonymous> (/Users/me/work/github/node-forever-gui/server/socket_test.js:3:30)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Object..js (/usr/local/lib/node_modules/node-dev/lib/hook.js:52:17)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/usr/local/lib/node_modules/node-dev/lib/wrap.js:47:1)
    at Module._compile (module.js:456:26)

All modules are installed through npm. Please help me figure this out!

Problem courtesy of: Nikolay Dyankov


The is exactly what is stated, io is not a function and you can't pass a HTTP object to it. Use the listen method instead to attach Socket.IO to a HTTP instance.

var io = require('').listen(server);

For your second error, the file is a script, and has an extension. Add the .js to the reference.

<script src="/"></script>
Solution courtesy of: hexacyanide


There is currently no discussion for this recipe.

This recipe can be found in it's original form on Stack Over Flow.