Sockets are extremely useful when you’re implementing backend services in a Node.js application. They allow a service on one system to communicate with a service on another system through an IP address and port. The also provide the ability to implement an IPC between two different processes running on the same server. The net
module allows you to create Server
objects that act as socket servers and Socket
objects that act as socket clients. Because the Socket
object extends Duplex
streams, you can read and write data from both the server and client. For secure connections, Node.js provides the tls
module, which allows you to implement secure TLS socket servers and clients.