I want to use the emit event in the express router, so I am trying to pass a global.io.
But the problem is , even if I add this code
io.emit('join','Tudis')
in the server.js , I can't see any response output,
(I think there should be 'someone joined :Tudis' right after compiling?) please enlighten me , thank you so much.
-----the code of server.js---------
const express = require('express')
const socketio=require('socket.io')
const http=require('http')
const serverPORT=5000
const app = express();
const server = http.createServer(app)
const io=socketio(server)
io.on('connection',(socket)=>{
socket.on('join',(name)=>{
console.log('someone joined :' + name)
})
})
global.io=io
const router=require('./router')
app.use(router)
io.emit('join','Tudis')
server.listen(serverPORT,
()=> console.log('server is up at : '+serverPORT)
)