I'm trying to emit a message server side in Node.JS using Socket.io.
The socket.io connection is made in the app.js script.
The message is emitted in server.js script.
However I keep getting the error 'TypeError: io.emit is not a function'.
What could be the problem?
Thanks in advance!
app.js:
const app = require('./server'); // Fetch APIs
const socket = require("socket.io");
const port = 6000; // Processing Port
// Port session listener
const server = app.listen(port, () => {
console.log(`App started on port ${port} ...!`)
})
// Socket setup
const io = socket(server);
// Export socket
module.exports={io};
server.js:
const { io } = require('socket.io-client');
....
....
....
io.emit('processing-progress',`App has started ..!`);