How to mock web servers using Node.js - Part 2: Websockets server

In Part 1, we explored how to mock web servers with Node.js using HTTP. In Part 2, we create a WebSockets server to allow for full-duplex communications between the client and server. The great thing about the node project is that with a single project we can create as many servers as we would like. So, we can continue to use the project from part 1 to build our second server.

How to mock web servers using Node.js - Part 1: HTTP


When developing web applications one challenge is web server mocking. If you are writing an application that ultimately relies on a connection to a web server how do you effectively stand up a mock server? In the past many developers would rely on the standards, Microsoft IIS and Apache for example, which are separate applications running locally or on a development server. But the big issue here is dynamically changing their configurations – a primary requirement of mock environments. This is hard to achieve since these are separate applications tightly integrated with the local operating system and keep under lock and key by rigid security protocols.

Topics: HTTP, Node.js