Let’s test the new functionality. Make sure that
nodemon
has reloaded your code. (If you need
to, you can manually stop nodemon
with Control-C and restart it with
npm run dev
.)
Open a third terminal window and run the command
wscat -c http://localhost:3001
.
(You should have one terminal running nodemon
and two running wscat
.)
Enter some chat messages in the two windows connected to the server.
After you have chatted with yourself for a bit, open a fourth terminal and run
wscat -c http://localhost:3001
. This chat
client should be sent all the previous messages.
If everything went well, you should see something like Figure 16.4.
Congratulations! You have written a fully functional chat server using WebSockets – and it took less than two dozen lines of JavaScript.
3.143.5.201