Categories
JavaScript Answers

How to use pipe() in Node.js net?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published.