Late in 2016, I began development on a lightweight, isomorphic WebSocket library for Node.js called ws-wrapper. Today, this library is stable and has been successfully used in many production apps.
Why? What about socket.io? In my opinion, socket.io and its dependencies are way too heavy. Now that the year is 2018, this couldn't be more true. Modern browsers have native WebSocket support meaning that all of the transports built into the socket.io project are just dead weight. On the other hand, ws-wrapper and its dependencies weigh about 3 KB when minified and gzipped. Similarly, ws-wrapper consists of about 500 lines of code; whereas, socket.io consists of thousands of lines of code. As Dijkstra once famously said: "Simplicity is prerequisite for reliability."
ws-wrapper also provides a few more features out of the box. The API exposes a two-way, Promise-based request/response interface. That is, clients can request data from servers just as easily as servers can request data from clients -- all using a modern, Promise-based API.
Tip: When using ws-wrapper on a Node.js server, it is better to utilize ws-server-wrapper on the server-side, which provides some extra functionality to keep track of inbound connections and uses ws-wrapper to wrap WebSockets under the hood.
Check out the example web application here: https://github.com/bminer/ws-server-wrapper/tree/master/example-app
Happy coding!
Why? What about socket.io? In my opinion, socket.io and its dependencies are way too heavy. Now that the year is 2018, this couldn't be more true. Modern browsers have native WebSocket support meaning that all of the transports built into the socket.io project are just dead weight. On the other hand, ws-wrapper and its dependencies weigh about 3 KB when minified and gzipped. Similarly, ws-wrapper consists of about 500 lines of code; whereas, socket.io consists of thousands of lines of code. As Dijkstra once famously said: "Simplicity is prerequisite for reliability."
ws-wrapper also provides a few more features out of the box. The API exposes a two-way, Promise-based request/response interface. That is, clients can request data from servers just as easily as servers can request data from clients -- all using a modern, Promise-based API.
Tip: When using ws-wrapper on a Node.js server, it is better to utilize ws-server-wrapper on the server-side, which provides some extra functionality to keep track of inbound connections and uses ws-wrapper to wrap WebSockets under the hood.
Check out the example web application here: https://github.com/bminer/ws-server-wrapper/tree/master/example-app
Happy coding!
Comments