Just a small test thing to experiment with websocket.
Alrighty then! Follow these steps:
- Run
npm install
to install dependencies. - Run the project with
npm start
. - Open localhost:8080 in your browser
- Enter a name and then send some messages!
- Open the page in another tab to watch the message come to there as well!
- You can use
npx nodemon
instead ofnpm start
, however this means changing websocket code will restart the server and drop the connections. That will be difficult to catch on so I don't recommendnodemon
ing this. - You can use the enviroment variable
PORT
to change the default port8080
. - On client side, try reading Websocket class documentation on MDN. On server side, try reading ws.js' documentation. Typescript types also helps but those are the last resorts.