From the course: Node.js: Web Servers, Tests, and Deployment

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Broadcasting messages with a WebSocket

Broadcasting messages with a WebSocket - Node.js Tutorial

From the course: Node.js: Web Servers, Tests, and Deployment

Broadcasting messages with a WebSocket

- [Instructor] In the last lesson, we started building the socket server for a browser based chat application. Now the front end team, as we saw, had delivered this client folder that had a bunch of static assets in it that we needed to set up a server behind. So let's go ahead and start that client. We're going to do so with npx serve. We'll use ./client for the name of the directory. And then we'll also pass a port with the -p flag so that this will run on localhost 5000. So now, if we go back to our application, localhost 5000 doesn't have a server. We need to run our server with node server. Now, if we hit refresh, we should see that a new socket has been connected and this will occur for any other tab that I open up. So notice that when I start to type messages, those are not captured anywhere. Nothing is happening. So what we want to do next is we want to create a new array of messages that we can populate. And…

Contents