BoB
BoB

Reputation: 11

nodejs stdin, data event never triggers

Input data event not triggering.

server.js

const net = require('node:net');
const { stdin: input, stdout: output } = require('node:process');


const TCPServer = net.createServer().listen({port: 3000});

TCPServer.on('connection', (socket) => {
    socket.pipe(input);
    input.on('data', (chunk) => console.log('data arrived'));
});

client.js

const net = require('node:net');
const { stdin: input, stdout: output } = require('node:process');

const clientSocket = net.createConnection({port: 3000});

input.pipe(clientSocket);
clientSocket.pipe(output);

The data is showed in the terminal but the input 'data' event never triggers. I already tried input.resume() and it doesn't worked + writeable.writeable is resumed anyway. Any ideas what's wrong?

Upvotes: 1

Views: 16

Answers (0)

Related Questions