Writing the server

To add interaction to the application, we must create the server first. We will use the ws package to easily create a websocket server. On the websocket, we can send messages in both directions. These messages are objects converted to strings with JSON, just like in the previous chapters.

Connections

In the previous chapter, we wrote a connectionless server. For every request, a new connection was set up. We could store a state using a session. Such session was identified with a cookie. If you were to copy that cookie to a different computer, you would have the same session there.

Now we will write a server that uses connections. In this way, the server can easily keep track of which user is logged in and where. The server can ...

Get TypeScript: Modern JavaScript Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.