Creating a server like pusher using websocket nodejs

I have a big question regarding Websocket.

Well, let’s go..
What am I needing? I need to add in my application a way to notify my user in real time about things that happen in the backend, for example, let’s say that some administrator has updated the user’s data, then that same user needs to receive a notification saying that the data has changed.

Challenges in this process.
1st – I need to save a unique ID of the user connected to the websocket, for that I’m using the “getUniqueID” function that I’ve seen in other posts, the question in this case would be, could I save the id that was generated in the database referring to the logged in user? is it a good alternative?

2nd I need that when the registry is updating send the message to the user, in case I need to trigger the notification coming from the Controller, the question is, how do I access the WSS variable once it was instantiated when the server was turned on?

Below I’m putting my 2 files that I’m using to turn on the server.

appSocket.js

import WebSocket from "ws";
import { Server } from "socket.io";

function onError(ws, err) {
    console.error(`onError: ${err.message}`);
}

function onMessage(ws, data) {
    console.log(`onMessage: ${data}`);
    ws.send(`recebido!`);
}

function onConnection(ws, request) {     
    ws.on('message', data => onMessage(ws, data));
    ws.on('error', error => onError(ws, error));
    ws.id = request.headers['sec-websocket-key']; 
    console.log("WS ID = "+ws.id)
}

export default (server) => {
    // const wss = new Server(server);
    const wss = new WebSocket.Server({
        server
    });

    wss.getUniqueID = function () {
        function s4() {
            return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
        }
        return s4() + s4() + '-' + s4();
    };
    
    wss.on('connection', onConnection);

    console.log(`App Web Socket Server is running!`);
    return wss;
}

My App.js

// import app from './app';
import appWs from './app-socket';
import express from 'express';
import cors from 'cors';
import helmet from 'helmet';
import morgan from 'morgan';
import dotenv from 'dotenv';
import {i18n} from './i18n';
import routes from './routes';
import bodyParser from 'body-parser';

var multer = require('multer');
var upload = multer();
const path = require('path');
dotenv.config();

class App {
    constructor() {
      this.express = express();
  
      this.database();
      this.middlewares();
      this.routes();
    
      const server = this.express.listen(process.env.PORT || 3000, () => {
        console.log(`Welcome to  => PORT ${process.env.PORT || 3000}`);
      });

      appWs(server);
    }
  
    database() {
      //      
    }
  
    middlewares() {
      this.express.use(cors({ origin: process.env.CORS_ORIGIN || '*' }));
      this.express.use(helmet());      
      this.express.use(morgan('dev'));
      this.express.use(express.json());      
      this.express.use(express.static(path.join(__dirname,'public')));
      // for parsing application/json
      this.express.use(bodyParser.json()); 
      // for parsing application/xwww-
      this.express.use(bodyParser.urlencoded({ extended: true })); 
      //form-urlencoded
      // for parsing multipart/form-data
      this.express.use(upload.array()); 

      let appExpress = this.express;
      i18n.init({ appExpress });     
    }
  
    routes() {
      this.express.use(routes);
    }
  }
  export default new App().express;