Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8602965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:12:49+00:00 2026-06-12T02:12:49+00:00

im trying to build a simple application with express@3.0.0rc4 , and socket.io@0.9.10 . Ive

  • 0

im trying to build a simple application with express@3.0.0rc4, and socket.io@0.9.10.

Ive generate the skel of my app with express generator:

express --sessions --css stylus --ejs myapp

I edited then the package.json file to include socket.io:

{
  "name": "application-name",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node app"
  },
  "dependencies": {
    "express": "3.0.0rc4",
    "ejs": "*",
    "stylus": "*",
    "socket.io": "*"
  }
}

and ran npm install.
Socket.io got installed correctly.

I opened the app.js file, required socket.io, set it to listen the server, but when adding event handlers with

io.sockets.on('connection', callback.. bla bla bla);

I get

io.sockets.on('connection', function(socket) {
           ^
TypeError: Cannot call method 'on' of undefined

I get

   info  - socket.io started

when running, so socket.io is initializing, but there doesnt seems to be a io.sockets module.

Ive ran console.log(io); to explore the object and I got:

{ version: '0.9.10',
  protocol: 1,
  clientVersion: '0.9.10',
  listen: [Function],
  Manager: 
   { [Function: Manager]
     defaultTransports: [ 'websocket', 'htmlfile', 'xhr-polling', 'jsonp-polling' ] },
  Transport: [Function: Transport],
  Socket: [Function: Socket],
  Static: [Function: Static],
  Store: { [Function: Store] Client: [Function] },
  MemoryStore: { [Function: Memory] Client: [Function: Client] },
  RedisStore: { [Function: Redis] Client: [Function: Client] },
  parser: 
   { packets: 
      { disconnect: 0,
        connect: 1,
        heartbeat: 2,
        message: 3,
        json: 4,
        event: 5,
        ack: 6,
        error: 7,
        noop: 8 },
     reasons: 
      { 'transport not supported': 0,
        'client not handshaken': 1,
        unauthorized: 2 },
     advice: { reconnect: 0 },
     encodePacket: [Function],
     encodePayload: [Function],
     decodePacket: [Function],
     decodePayload: [Function] } }

So where is the sockets method? Nowhere. But look, there is a Socket function:

Socket: [Function: Socket]

So I thought maybe documentation is deprecated and sockets became Socket.
So I did console.log(io.Socket); and got

  this.id = id;
  this.namespace = nsp;
  this.manager = manager;
  this.disconnected = false;
  this.ackPackets = 0;
  this.acks = {};
  this.setFlags();
  this.readable = readable;
  this.store = this.manager.store.client(this.id);
  this.on('error', defaultError);

But that Socket.on doesnt seems to be the function im looking.

So how do I set the handlers?
At the webpage, github and resources out there all of them uses io.sockets.on().

Notice that I also tried running npm install socket.io separatly

I’ll post my app.js just in case, but It doesnt seems to be a problem with my code:

var express = require('express')
  , routes = require('./routes')
  , user = require('./routes/user')
  , http = require('http')
  , path = require('path')
  , io = require('socket.io');

var app = express();

app.configure(function(){
  app.set('port', process.env.PORT || 3000);
  app.set('views', __dirname + '/views');
  app.set('view engine', 'ejs');
  app.use(express.favicon());
  app.use(express.logger('dev'));
  app.use(express.bodyParser());
  app.use(express.methodOverride());
  app.use(express.cookieParser('your secret here'));
  app.use(express.session());
  app.use(app.router);
  app.use(require('stylus').middleware(__dirname + '/public'));
  app.use(express.static(path.join(__dirname, 'public')));
});

app.configure('development', function(){
  app.use(express.errorHandler());
});

app.get('/', routes.index);
app.get('/users', user.list);

var server = http.createServer(app).listen(app.get('port'), function(){
  console.log("Express server listening on port " + app.get('port'));
});

io.listen(server);

console.log(io.Socket);


io.sockets.on('connection', function(socket) {
  socket.emit('init', { msg: 'Welcome'});
  socket.on('roll', function(data) {
    console.log(data);
  })
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T02:12:50+00:00Added an answer on June 12, 2026 at 2:12 am
    var app = require('express')()
      , http = require('http')
      , server = http.createServer(app)
      , io = require('socket.io').listen(server)
    
    server.listen(3000)    
    
    io.on('connection',function(socket){
      console.log('connection..')
    })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to build a simple booking application for a school presented as
I'm trying to build a simple c application using gcc on aix gcc -I.
I'm trying to build a simple GAE application that would read a textbox, pass
I'm trying to build a simple HTML text editor in a Windows Form application.
I'm trying to build a simple application, with the finished program looking like this
Hello dearest community, I am trying to build a simple AutoUpdate application using VB.NET.
I'm trying to build a simple product backlog application to teach myself Rails. For
Im trying to build a simple XML to Controls parser in my CF application.
I'm trying to build a simple form in a c++ win32 console application. instead
I'm trying to build a simple proof-of-concept business application in Silverlight and I keep

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.