Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save mrhung/503fe0c6f79dbc5f24e835ef1c3dadc1 to your computer and use it in GitHub Desktop.

Select an option

Save mrhung/503fe0c6f79dbc5f24e835ef1c3dadc1 to your computer and use it in GitHub Desktop.

Revisions

  1. @laterbreh laterbreh renamed this gist Jan 4, 2016. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. @laterbreh laterbreh revised this gist Dec 25, 2015. 1 changed file with 0 additions and 4 deletions.
    4 changes: 0 additions & 4 deletions Other Sources:
    Original file line number Diff line number Diff line change
    @@ -1,4 +0,0 @@
    ////////////////////////////////////////////
    Other sources of information on this topic:
    ////////////////////////////////////////////
    http://stackoverflow.com/questions/31016350/using-socket-io-with-express-4-generator
  3. @laterbreh laterbreh revised this gist Dec 25, 2015. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions Other Sources:
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    ////////////////////////////////////////////
    Other sources of information on this topic:
    ////////////////////////////////////////////
    http://stackoverflow.com/questions/31016350/using-socket-io-with-express-4-generator
  4. @laterbreh laterbreh revised this gist Dec 25, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion app.js
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    var app = express();
    app.io = require('socket.io')();

    var routes = require('./routes/index')(app.io, passport);
    var routes = require('./routes/index')(app.io);

    app.use('/', routes);
  5. @laterbreh laterbreh revised this gist Dec 25, 2015. No changes.
  6. @laterbreh laterbreh created this gist Dec 25, 2015.
    6 changes: 6 additions & 0 deletions app.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    var app = express();
    app.io = require('socket.io')();

    var routes = require('./routes/index')(app.io, passport);

    app.use('/', routes);
    17 changes: 17 additions & 0 deletions index.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    //Normal code here

    //then at the bottom:

    module.exports = function (io) {
    //Socket.IO
    io.on('connection', function (socket) {
    console.log('User has connected to Index');
    //ON Events
    socket.on('admin', function () {
    console.log('Successful Socket Test');
    });

    //End ON Events
    });
    return router;
    };
    18 changes: 18 additions & 0 deletions www
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    /**
    * Create HTTP server
    */

    var server = http.createServer(app);
    app.io.attach(server);
    /**
    * Listen on provided port, on all network interfaces.
    */

    server.listen(port);
    server.on('error', onError);
    server.on('listening', onListening);


    /**
    * Normalize a port into a number, string, or false.
    */