I am looking to write a couple of tcp servers/clients in node. I'm trying to figure out what node.js ecosystem provides for making such development easier. I'm thinking of something similar to parts of (java's) netty. That project provides a way to implement the protocol in a way that it can be plugged into the network code pipeline or taken out of actual tcp connection code to be tested independently.
Node's http frameworks often provide a middle-ware layer. Users can write code which intercepts requests or responses to isolate bits of functionality so the actual request/response interface doesn't change much. This results in 3rd party providers of such code which does logging, authentication, etc.
Does something like this exist for lower level networking code? (since my testing out some ideas, if someone knows of other non-java/c++/c# languages which DO provide such features/libraries, I'd like to read about them as well)
Since you tagged Elixir, I'll bite.
While Elixir has a great framework for building something like this for HTTP clients (Plug), an option I'd consider is using the vegur
and ranch_proxy_protocol
libraries (written in Erlang by Heroku, but easily used in Elixir), vegur
offers a pluggable middleware layer which are easily tested in isolation. I'm currently using this for a proxy layer at my company.
Even without those, building an application like this using ranch
would be very trivial. Ranch handles listening/accepting/reading/writing from sockets, and you could just insert a pluggable pipeline where needed, enforced using a behaviour (the Erlang/Elixir equivalent of an interface).
These types of applications are pretty much a sweet spot for Erlang and Elixir, I'd highly recommend it if you are familiar or interested in either one.
Not sure there are that many ready-made things available, but for the actual middleware pattern itself, there is ware which is generic middleware for use in any JavaScript context (Node, browser) and not coupled to HTTP.