socket.js 383 B

123456789101112
  1. //const {} = require('../db/models')
  2. const chalk = require("chalk");
  3. module.exports = io => {
  4. io.on("connection", socket => {
  5. socket.emit("welcome", "Websockets are awesome!");
  6. console.log(chalk.green(`[socket.io] Connection: ${socket.id}`));
  7. socket.on("disconnect", async () => {
  8. console.log(chalk.red(`[socket.io] Disconnect: ${socket.id}`));
  9. });
  10. });
  11. };