To use pipe() in Node.js net, we call the on
method.
For instance, we write
const net = require("net");
net.createServer((socket) => {
socket.write("Echo server\r\n");
socket.on("data", (chunk) => {
socket.write(chunk);
});
socket.on("end", socket.end);
});
to call createServer
to create a server.
We call write
to write a message.
And we call on
to listen for data.