- Clone repository.
- Run
npm i. - Run
node app.js.
Live example: https://chat-server.fbg.pl
- Install socket.io client:
npm i socket.io-client
- Initialize socket connection:
import * as io from 'socket.io-client';
// ...
const connection = io.connect('https://chat-server.fbg.pl');- Sending events:
connection.emit('chat message', { text: 'Message text', authorId: 'John Doe' });As a response you will receive:
{
authorId: 'John Doe',
id: 'huSfgxpQTy'
text: 'Message text'
timestamp: 1587727149888
}- Listening for the events:
connection.on('chat message', (message) => console.warn(message));