Using socket.io from a module

后端 未结 2 372
故里飘歌
故里飘歌 2021-01-12 23:36

My sio = require(\'socket.io\').listen(app) is in my server.js file, but I\'m calling a method in a library that would like to push a message to the client... s

2条回答
  •  攒了一身酷
    2021-01-13 00:03

    in server.js append this line

    module.exports.sio = sio; 
    

    in api/user.js

    sio = require('../server').sio;
    sio.sockets.on ...
    

    Or did I misunderstand the question?

提交回复
热议问题