title: WebSockts + Angular 5 + nodejs(express,Typescript) implementation
body: <p>I am using <strong>Express Typescript Boilerplate</strong> link "<a href="https://github.com/w3tecch/express-typescript-boilerplate" rel="nofollow noreferrer">https://github.com/w3tecch/express-typescript-boilerplate</a>" and angular 5 for client side</p>
  
  <h2>Problem : i am trying to implement WebSockets for real time table data.</h2>
  
  <p>when i am on a specific page i need the WebSocket connection to be established and if i redirect to another page the connection should be closed.
  The documentation for all the websocket implementations for node an angular totally focus on Chat single page applications.</p>
  
  <blockquote>
  <pre><code>    /**
       * We create a new Socket server instance.
       */
      const server = settings.getData('express_server');
      //server is express app instance saved globally using 
      //microframework-w3tec
      let io = undefined;
      if (io === undefined || io === null) {
          console.log('socket loader initialized');
          io = require('socket.io')();
          io.on('connect', (socket: any) =&gt; {
              console.log('a user connected');
              io.emit('message', 'this is message');
          });
          io.listen(server);
          io.on('add-message', (message) =&gt; {
              io.emit('message', { type: 'new-message', text: message 
       });
          });
          settings.setData('io', io);
  </code></pre>
  </blockquote>