title: nodejs, socket.io: how to get request and response from socket function?
body: <p>i m creating chat application, using nodejs (0.8.15), express (>3.0) framework and mongodb for register users.</p>
  
  <pre><code>var express = require('express')
    , http = require('http')
    , path = require('path')
    , io = require('socket.io');
  
  var app = express()
    , server = http.createServer(app)
    , io = io.listen(server);
  
      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('secret'));
        app.use(express.session({cookie: {maxAge: 60000*100}}));
        app.use(app.router);
        app.use(express.static(path.join(__dirname, 'public')));
      });
  
      app.configure('development', function() {
        app.use(express.errorHandler());
      });
  
      app.get('/chat', function(req, res) {
          res.render('chat');
      });
  
   server.listen(app.get('port'), function() {
      console.log("Express server listening on port " + app.get('port'));
    });
  
   io.sockets.on('connection', function (socket) {
      socket.on('start-chat', function() {
           // here i need to know req and res
           // for example, i need to write:
           // socket.username = req.session.username;
      });
   });
  </code></pre>
  
  <p>Q: How to get res and req objects to work with them when chatting like on code above? or am i going wrong way of creating chat with user auth?</p>
  
  <p>thank you!</p>
  
  <p>EDITED: answer is here
  <a href="http://www.danielbaulig.de/socket-ioexpress/" rel="noreferrer">http://www.danielbaulig.de/socket-ioexpress/</a></p>