Does node have built in support for Websockets?

Viewed 1954

I seem to be confused by conflicting sources, yesterday I was reading the node docs and was sure Node's 'net' and 'http' modules had web socket capabilities, but maybe I misunderstood the documentation because today an article said that node has no built in web socket support.

Can you create a node server that can handle web socket connections with just node and javascript, no external libraries?

2 Answers

Node does not have native support for websockets like it does for http or tcp (net) connections.

It's been discussed a few times, and rejected for various reasons of the last few years. The current discussion is going on here: https://github.com/nodejs/node/issues/19308

You can, of course, implement a websocket server yourself using the native modules, but you'll need to do a lot of boilerplate work.

To see both an example of what you'd need to do to implement your own websocket server using node and a good pre-built library you can use to work with websockets in node, I would reccomend taking a look at: https://github.com/websockets/ws

Sure, you could... if you re-implemented the functionality from those Web Socket libraries yourself.

The Node.js core libraries are minimal. They're only intended to cover the basics needed to function, and the most common use cases. As much functionality as possible is left to modules outside of the Node.js core. This is a very intentional design.

It would be incredibly irresponsible to implement your own Web Socket library without a very good reason. You should rethink why you don't want to use existing libraries.

Related