How to use socket.io within a control that is injected by the consign?

1

I have my file server.js :

const express = require( 'express' );
const expressValidator = require( 'express-validator' );
const expressSession = require( 'express-session' );
const consign = require( 'consign' );
const bodyParser = require( 'body-parser' );

const app = express();

app.use( bodyParser.urlencoded( { extended: true } ) );
app.use( bodyParser.json( { extended: true } ) );
app.use( expressValidator() );

consign()
   .include( 'app/controller' )
   .then( 'app/model' )
   .then( 'app/routes' )
   .then( 'config/dbConnection.js' )
   .into( app );

module.exports = app;

And the file app.js :

const app = require('./config/server');

const server = app.listen(80, () => console.log('Servidor online'));

const io = require('socket.io').listen(server);

io.on('connection', (socket) => {
console.log('Cliente conectado.');
socket.emit('news', { hello: 'bem vindo cabra!' });

socket.on('cliente', (data) => {
  console.log(data.my);
});
});

How do I use the io variable inside controls that are injected into app by consign ?

    
asked by anonymous 10.10.2018 / 14:39

0 answers