title: How to use socket.io in angular with node.js?
body: <p>Clientside I used Angular 6 and Serverside i used node.js.</p>
  
  <p>Here in angular 6 console it print message and
   <code>socket.io id({message: "Hello World", id: "6An-ctwlwbZZWrfMAAAB"})</code>
   after using below code.</p>
  
  <p>this code is right or any change in this code bcoz I am not sure about this code kindly help to make correct this. </p>
  
  <p>and another query is I have more than 15 components in my project so how to make common use this <code>socket.io</code> for all components or I have to import this <code>app.component.ts</code> code in all another component.</p>
  
  <p>app.js(serverside)</p>
  
  <pre><code>after installing (npm i socket.io)
  
  const express = require('express');
  var app = express();
  const http = require('http');
  const socketIo = require('socket.io');
  const server = http.Server(app);
  const io = socketIo(server);
  
  server.listen(3000,function(req,res){
    console.log("listen at 3000!");
  });
  
  io.on('connection',(socket) =&gt; {
    socket.emit('hello',{
      message : 'Hello World',id: socket.id
    })
  });
  </code></pre>
  
  <p>app.component.ts(clientside)</p>
  
  <pre><code>after installing (npm i socket.io)
  
  import * as socketIo from 'socket.io-client';
  
  export class AppComponent implements OnInit {
    ngOnInit(){
      const socket = socketIo('http://localhost:3000/');
        socket.on('hello',(data) =&gt; console.log(data));
      }
    }
  }
  </code></pre>