Socket io

Setup

Tutorial

  1. Make sure we are using an ES Module config Add this code to package.json
  "type": "module",
  "name": "esmodule-example",
  "version": "1.0.0",
  "main": "main.mjs",
  "scripts": {
    "start": "node main.mjs"
  }
npm i express@4
npm install socket.io
  1. Add the client side js
<script src="/socket.io/socket.io.js"></script>
<script>
  const socket = io();
</script>

CDN is available at

<script src="https://cdn.socket.io/4.7.4/socket.io.min.js"></script>

Emitting Events

Any object serializable to JSON and binary data is supported