June 2025
Intermediate to advanced
837 pages
24h 50m
English
Duplex streams represent a combination of readable streams and writable streams. You can read data from a duplex stream as well as write data into it. The write and read operations of a duplex stream are independent of each other, and each has its own buffer. A typical implementation of a duplex stream are network sockets as they are used in the net module.
Unfortunately, duplex streams can only be described quite abstractly. Much more understandable here, however, are concrete examples. Listing 18.17 contains source code that demonstrates the use of a duplex stream.
import { createServer } from 'net'; createServer((socket) => { socket.on('readable', () => { const data = socket.read();
Read now
Unlock full access